没看到题目条件可以重复边。。。。

已ac

#include<bits/stdc++.h>
using namespace std;
int d[100005],g[10005][10005];
bool vis[100005];
// n点数 m边数 s起点 u,v端点 w权
int n,m,s,u,v,w;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
int main(){
   fill(d+1,d+10000,INT_MAX);
   cin>>n>>m>>s;
   //input
   for(int i=1;i<=m;i++){
      cin>>u>>v>>w;
      g[u][v]=w;
   }
   d[s]=0;
   q.push({0,s});
   while(!q.empty()){
      //取出MIN_DISTANCE的节点
      int dis=q.top().first;
      int node=q.top().second;
      q.pop();
      //已经处理过
      if(vis[node]){
         continue;
      }
      vis[node]=true;
      for(int i=1;i<=n;i++){
         if(g[node][i]&&dis+g[node][i]<d[i]){
            d[i] = dis+g[node][i];
            q.push({d[i],i});
         }
      }
   }
   for(int i=1;i<=n;i++){
      cout<<d[i]<<" ";
   }
   return 0;
}

1ac

0 comments

No comments so far...

Information

ID
1838
Time
1000ms
Memory
256MiB
Difficulty
3
Tags
# Submissions
16
Accepted
5
Uploaded By