xtr169 @ 2024-11-28 20:17:24
P4779(最短路模版题)
关于几乎都WA了
看了半个小时愣是没看出来
帮助一定会关注
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
using namespace std;
int n,m,s,u,v,w,d[1000005],vis[1000005],pos,y,l;
vector< pair <int,int> > E[1000005];
priority_queue< pair<int,int> > pq;
pair<int,int> now;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m>>s;
for(int i=1;i<=n;i++) d[i]=1e10;
for(int i=1;i<=m;i++)
{
cin>>u>>v>>w;
E[u].pb(mp(w,v));
}
d[s]=0;
pq.push(mp(0,s));
while(!pq.empty())
{
now=pq.top();pq.pop();
pos=now.sec;
if(vis[pos]) continue;
vis[pos]=1;
for(int i=0;i<E[pos].size();i++)
{
y=E[pos][i].sec;l=E[pos][i].fir;
if(d[y]>d[pos]+l)
{
d[y]=d[pos]+l;
pq.push(mp(d[y],y));
}
}
}
for(int i=1;i<=n;i++)
{
cout<<d[i]<<" ";
}
return 0;
}
by xtr169 @ 2024-11-28 20:32:42
@立柱已选162534
太感谢了
我傻了~~~
已关注