| 比赛 | 
    20110722 | 
    评测结果 | 
    AWAWAWAAAAAAAAAAA | 
    | 题目名称 | 
    网络探测 | 
    最终得分 | 
    82 | 
    | 用户昵称 | 
    .Xmz | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2011-07-22 08:29:04 | 
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn=1111;
const int oo=1000000000;
struct edge
{
	int t,c;
	edge *next;
}E[maxn*maxn*2],*V[maxn];
int eh,S,T,n,m;
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()
{
	S=0;
	scanf("%d%d%d",&n,&m,&T);
	int a,b,c;
	for (;m;--m)
	{
		scanf("%d%d%d",&a,&b,&c);
		addedge(a,b,c);
	}
}
int d[maxn],inq[maxn];
queue <int> Q;
void spfa()
{
	for (int i=0;i<n;i++) d[i]=oo;
	d[S]=0;
	Q.push(S);inq[S]=true;
	while (Q.size())
	{
		int u=Q.front();
		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]) Q.push(e->t),inq[e->t]=true;
			}
		}
		Q.pop();inq[u]=false;
	}
}
int main()
{
	freopen("ping.in","r",stdin);
	freopen("ping.out","w",stdout);
	init();
	spfa();
	if (d[T]==oo) printf("no\n");
	else printf("%d\n",d[T]);
	return 0;
}