The Beautiful Path
来源:互联网 发布:天刀男性捏脸数据导入 编辑:程序博客网 时间:2024/06/06 06:30
The Beautiful PathTime Limit: 10000ms, Special Time Limit:25000ms, Memory Limit:65536KBTotal submit users: 10, Accepted users: 1Problem 13771 : No special judgementProblem descriptionThere is an undirected graph with n nodes and m edges.There maybe have multipul edges and selfcycle.Now there is a trip from node a to node b.XiaoMing want to know how much time it will take at least ,and in this case , how many edges he will pass at least.InputThere are lots of case.
For each test case.Only one line contains four integers n,m(n<=100000, 1<=m<=200000)a,b ( a<= n b<=n ), which indicates the number of nodes and number of edges, the start node and the end node.
The next m lines describe the graph.OutputFor each test case, you output the minimul time and the minimul edge nums in one line “Case #%d: %d %d” Sample Input
For each test case.Only one line contains four integers n,m(n<=100000, 1<=m<=200000)a,b ( a<= n b<=n ), which indicates the number of nodes and number of edges, the start node and the end node.
The next m lines describe the graph.OutputFor each test case, you output the minimul time and the minimul edge nums in one line “Case #%d: %d %d” Sample Input
10 20 4 71 2 82 3 41 4 72 5 103 6 32 7 11 8 43 9 12 10 38 9 21 3 108 4 33 10 610 9 37 4 810 3 210 2 49 8 51 6 52 7 4Sample Output
Case #1: 8 1Problem Source
The 13th Programming Contest ofHunan University, 2017
#include<iostream>#include<stdio.h>#include<string.h>#include<vector>#include<queue>using namespace std;const int inf=0x3f3f3f3f;int n,m,s,e;struct edge{ int v,w; edge(int V,int W){ v=V,w=W; } edge(){}};vector<edge> u[100005];queue<int> q;bool vis[100005];int dis[100005],sum[100005];void spfa(){ for(int i=1;i<=n;i++) vis[i]=0,dis[i]=inf; q.push(s);vis[s]=1,dis[s]=0; while(!q.empty()){ int uu=q.front();q.pop(); vis[uu]=0; int siz=u[uu].size(); for(int i=0;i<siz;i++){ int vv=u[uu][i].v,ww=u[uu][i].w; if(dis[vv]>dis[uu]+ww){ dis[vv]=dis[uu]+ww; if(!vis[vv]) vis[vv]=1,q.push(vv); } } }}void bfs(){ for(int i=1;i<=n;i++) vis[i]=0,sum[i]=0; q.push(s);vis[s]=1; while(!q.empty()){ int uu=q.front();q.pop(); vis[uu]=0; int siz=u[uu].size(); for(int i=0;i<siz;i++){ int vv=u[uu][i].v,ww=u[uu][i].w; if(dis[vv]==dis[uu]+ww){ sum[vv]=sum[uu]+1; if(!vis[vv]){ vis[vv]=1; q.push(vv); } } } }}int main(){ int cas=0; while(scanf("%d%d%d%d",&n,&m,&s,&e)!=EOF){ for(int i=1;i<=n;i++) u[i].clear(); for(int uu,vv,ww,i=0;i<m;i++){ scanf("%d%d%d",&uu,&vv,&ww); u[uu].push_back(edge(vv,ww)); u[vv].push_back(edge(uu,ww)); } spfa(); bfs(); printf("Case #%d: %d %d\n",++cas,dis[e],sum[e]); }}
0 0
- The Beautiful Path
- The Beautiful Sentences
- The buji particularly beautiful sunset
- The Most Beautiful Equation (Remix)
- swjtu2385(Maximize The Beautiful Value)
- Beautiful
- Hangzhou, the most beautiful city in China.
- The Principles of Beautiful Web Design [ILLUSTRATED]
- Careercup Facebook Keep the number beautiful...
- HDU 4346 The Beautiful Road 思路题
- enjoy the beautiful linux kernel code
- swjtu 2385 Maximize The Beautiful Value
- swjtuoj 2385 Maximize The Beautiful Value
- [Reprinted] the more beautiful the more sleep regimen 【Photo 15】
- The Serenity Path
- hdu2807---The Shortest Path
- The web project path
- The Path is Relative
- java__if从大到小排列
- JAVA中的GC机制详解 (一)
- android手机分辨率,xDpi,yDpi,尺寸等各种相关物理参数
- HDU 1003 Max Sum
- mysql5.7.14解压版的安装
- The Beautiful Path
- Ubuntu 10.04内核源码树的编译和安装
- android:descendantFocusability——父容器和子控件的焦点获取问题
- 正则表达式的相关知识
- Sublime Text3--打造完美的Markdown编辑器
- 守护进程(精灵进程)
- 1.8.ARM裸机第八部分-按键和CPU的中断系统
- java__if摄氏温度转化华氏温度
- 搭建ssm请假系统遇到的问题