比赛 |
20110414pm |
评测结果 |
ATWWWWWWTT |
题目名称 |
龙凡 |
最终得分 |
10 |
用户昵称 |
.Xmz |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2011-04-14 15:35:15 |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
using namespace std;
const int maxm=444444;
const int maxn=111111;
const int oo=2000000000;
struct edge
{
int t,c;
edge *next;
}E[maxm],*V[maxn];
int eh,n;
inline void addedge(int a,int b,int c)
{
E[++eh].next=V[a]; V[a]=E+eh; V[a]->t=b; V[a]->c=c;
E[++eh].next=V[b]; V[b]=E+eh; V[b]->t=a; V[b]->c=c;
}
void init()
{
int m,a,b,c;
scanf("%d%d",&n,&m);
for (;m>0;--m)
{
scanf("%d%d%d",&a,&b,&c);
addedge(a,b,c);
}
}
queue <int> Q;
bool inq[maxn];
int d[maxn],ans[maxn];
void solve()
{
Q.push(1);
inq[1]=true;
for (int i=1;i<=n;i++) d[i]=oo;
d[1]=0;
while (Q.size())
{
int u=Q.front();
Q.pop();inq[u]=false;
for (edge *e=V[u];e;e=e->next)
{
if (d[e->t]>d[u]+e->c)
{
d[e->t]=d[u]+e->c;
if (!inq[e->t])
{
inq[e->t]=true;
Q.push(e->t);
}
}
}
}
for (int i=1;i<=n;i++) ans[i]=oo;
for (int u=1;u<=n;u++)
for (edge *e=V[u];e;e=e->next)
if (d[u]+e->c>d[e->t] && d[u]+e->c<ans[e->t])
{
ans[e->t]=d[u]+e->c;
}
for (int i=2;i<=n;i++)
{
if (ans[i]==oo) ans[i]=-1;
printf("%d\n",ans[i]);
}
}
int main()
{
freopen("travel.in","r",stdin);
freopen("travel.out","w",stdout);
init();
solve();
return 0;
}