#include<cstdio> #include<iostream> #include<cstdlib> #include<iomanip> #include<cmath> #include<cstring> #include<string> #include<algorithm> #include<time.h> #include<queue> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pr; const double pi=acos(-1); #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,n,a) for(int i=n;i>=a;i--) #define Rep(i,u) for(int i=head[u];i;i=next[i]) #define clr(a) memset(a,0,sizeof a) #define pb push_back #define mp make_pair #define fi first #define sc second ld eps=1e-9; ll pp=1000000007; ll inf=2147483647; #define maxn 5005 #define maxm 200005 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;} ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;} ll read(){ ll ans=0; char last=' ',ch=getchar(); while(ch<'0' || ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; return ans; } //head int n,m,s; int dis[10005],vis[10005],head[10005],cnt; struct Edge { int next,dis,to; }edge[9999999]; queue <int> q; inline void add_edge(int from,int to,int dis) { cnt++; edge[cnt].next=head[from]; edge[cnt].to=to; edge[cnt].dis=dis; head[from]=cnt; } void spfa() { rep(i,1,n) dis[i]=inf; dis[s]=0; vis[s]=1; q.push(s); while(!q.empty()) { } } int main() { scanf("%d %d %d",&n,&m,&s); for(int i=1;i<=m;++i) { int u,v,d; scanf("%d %d %d",&u,&v,&d); add_edge(u,v,d); } spfa(); for(int i=1;i<=n;++i) { if(i==s) printf("0 "); else printf("%d ",dis[i]); } return 0; }
SPFA(未完待续)
猜你喜欢
转载自www.cnblogs.com/lcezych/p/10759139.html
今日推荐
周排行