UVa 10986 - Sending email
来源:互联网 发布:初中数学教学软件 编辑:程序博客网 时间:2024/06/08 02:09
链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1927
//邻接表+队列
#include <iostream>#include <string.h>#include <queue>#include <stdio.h>using namespace std;#define edge_max 100005#define vertex_max 100005const int inf = (1<<20);struct Node{ int u,w; int next;}Edge[edge_max];int pre[vertex_max],dist[vertex_max]; //以p[i]的i为起点储存的边数序号int n,m,start,stop; //顶点数,边数 起点,终点bool vis[vertex_max]; //记录void init(){ memset(pre,-1,sizeof(pre)); int index=1; int v,u,w; for(int i=0;i<m;i++) { scanf("%d%d%d",&v,&u,&w); Edge[index].u=u; Edge[index].w=w; Edge[index].next=pre[v]; pre[v]=index++; swap(v,u); Edge[index].u=u; Edge[index].w=w; Edge[index].next=pre[v]; pre[v]=index++; }}void spfa(int v){ queue <int> q; fill(dist,dist+n,inf); memset(vis,0,sizeof(vis)); dist[v]=0; vis[v]=1; while(!q.empty()) q.pop(); q.push(v); while(!q.empty()) { int top=q.front(); q.pop(); vis[top]=0; for(int i=pre[top];i!=-1;i=Edge[i].next) { int e=Edge[i].u; if(dist[e]>dist[top]+Edge[i].w) { dist[e]=dist[top]+Edge[i].w; if(!vis[e]) { q.push(e); vis[e]=1; } } } }}int main(){ int t,cnt=1; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&n,&m,&start,&stop); init(); spfa(start); printf("Case #%d: ",cnt++); if(dist[stop]!=inf) printf("%d\n",dist[stop]); else printf("unreachable\n"); } return 0;}
0 0
- uva 10986 - Sending email
- UVA 10986 - Sending email
- UVa:10986 Sending email
- UVA - 10986 Sending email
- UVa 10986 - Sending email
- UVa 10986 - Sending email
- UVA 10986 Sending email(SPFA)
- UVA 10986 Sending email SPFA
- UVA 10986 Sending email DIJSKRA(稀疏图)
- UVa 10986 - Sending email (Dijkstra优化, SPFA)
- uva 10986 - Sending email(最短路Dijkstra)
- uva 10986 Sending email (dijkstra)
- UVA 10986Sending email 【dijkstra + 堆优化】
- UVA 10896 Sending Email
- UVa 10986 Sending email / 优先队列优化dijkstra
- UVA - 10986 Sending email 最短路的spfa算法
- Sending email - UVa 10986 Dijkstra+优先队列优化
- UVa 10986 Sending email (最短路+Dijkstra队列优化)
- 软件测试成长之路001
- Majority Element II
- Android Studio使用技巧
- (一)PHP面向对象理论1---类
- USACO Arithmetic Progressions(暴力)
- UVa 10986 - Sending email
- QTP里的DOM应用
- 计算客 自建物流的wu人机实验(简单)(状态压缩+LCA)
- Sublime Text使用简介
- c语言指针的复习
- 1057: [ZJOI2007]棋盘制作(悬线法)
- wyh2000 and pupil
- vim命令,及vimrc设置参数
- Hadoop—Hive部署测试(含MySql部署)---练习9