wangchuanle @ 2024-04-20 20:30:13
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dis[200005];
typedef pair<ll,ll> P;
ll n,m,s,u,v,w;
struct data{ll to,w;};
vector<data>head[200005];
int main()
{
scanf("%lld%lld%lld",&n,&m,&s);
for(int i=1;i<=m;i++)
{
scanf("%lld%lld%lld",&u,&v,&w);
head[u].push_back((data){v,w});
}
priority_queue<P,vector<P>,greater<P> >Q;
memset(dis,127,sizeof dis);
dis[s]=0;
Q.push(P(0,s));
while(Q.size())
{
P p=Q.top();Q.pop();
int u=p.second;
for(int i=0;i<head[u].size();i++)
{
int to=head[u][i].to,w=head[u][i].w;
if(dis[to]>dis[u]+w)
{
dis[to]=dis[u]+w;
Q.push(P(dis[to],to));
}
}
}
for(int i=1;i<=n;i++)
printf("%lld ",dis[i]);
return 0;
}
by endswitch @ 2024-04-20 20:46:06
你的代码的 vis
始终为 false
怎么能不 T?
by queenbee @ 2024-04-20 20:46:21
@endswitch 害得是dalao
by wangchuanle @ 2024-04-20 20:48:36
@queenbee 蟹蟹
by wangchuanle @ 2024-04-20 20:50:03
@endswitch xiexie