hdu2544 spfa 第一弹 如果让我说:我只能说,实力决定一切
2013-04-22 12:29
465 查看
#include<iostream> #include<algorithm> #include<stack> #include<cstdio> #include<queue> #include<string.h> #define inf 1<<30 using namespace std; int N,M,T; int dis[201]; int vis[201]; int head[201]; queue<int>S; struct Edge { int to,w,next; }e[20010]; void init() { memset(head,-1,sizeof(head)); memset(vis,0,sizeof(vis)); for(int i=0; i<=N; i++) dis[i]=inf; dis[1]=0; } void Build_Tree(int u,int v,int weight) { e[T].to=v; e[T].w=weight; e[T].next=head[u]; head[u]=T++; } int spfa(int pox) { int tem; S.push(pox); while(!S.empty()) { tem=S.front(); S.pop(); vis[tem]=0; for(int i=head[tem]; i!=-1; i=e[i].next) { int t=e[i].to; if(dis[t]>dis[tem]+e[i].w) { dis[t]=dis[tem]+e[i].w; if(!vis[t]) { S.push(t); vis[t]=1; } } } } return dis ; } int main() { int Tu,Tv,Tweight; while(scanf("%d%d",&N,&M),N+M) { T=0; init(); for(int i=0; i<M; i++) { scanf("%d%d%d",&Tu,&Tv,&Tweight); Build_Tree(Tu,Tv,Tweight); Build_Tree(Tv,Tu,Tweight); } printf("%d\n",spfa(1)); } return 0; }
相关文章推荐
- hdu3339 spfa()+dp 如果让我说:我只能说,实力决定一切
- hdu1535 spfa() 如果让我说:我只能说,实力决定一切
- hdu2112 spfa() 如果让我说:我只能说,实力决定一切
- hdu2767强连通+缩点 如果让我说:我只能说,实力决定一切
- poj1679 判断最小生成树是不是唯一? 如果让我说:我只能说,实力决定一切。
- poj3974 hdu3068最长回文子串 如果让我说:我只能说,实力决定一切
- hdu1269强连通水题 如果让我说:我只能说,实力决定一切
- hdu 3191 次短路+优先队列 如果让我说:我只能说,实力决定一切
- hdu2594 今早1A 题目不错=~~= 如果让我说,我只能说,实力决定一切
- poj3463 hdu1688 次短路+优先队列 如果让我说:我只能说,实力决定一切
- hdu 3336 KMP走起 如果让我说:我只能说,实力决定一切
- poj2553强连通+缩点 如果让我说:我只能说,实力决定一切
- hdu 1233 kruskal+优先队列 如果让我说:我只能说,实力决定一切。
- hdu 2642 二维数组+判重 如果让我说:我只能说,实力决定一切
- poj 2752 KMP+DFS() 如果让我说:我只能说,实力决定一切
- hdu1247 字典树 单词拆分 如果让我说:我只能说,实力决定一切
- hdu1301 MST+优先队列 如果让我说:我只能说,实力决定一切。
- poj2186 强连通+缩点 如果让我说:我只能说,实力决定一切
- hdu1102 prime()和kruskal()两种方法,感觉不错。 如果你要问我:我只能说,实力决定一切
- hdu3746 KMP之next[]威武 如果让我说:我只能说,实力决定一切。