HDU
来源:互联网 发布:赵氏孤儿知乎 编辑:程序博客网 时间:2024/05/18 12:02
Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated his
fences they were separated into different blocks. John’s farm are divided into nn blocks labelled from 11 to nn.
Bessie lives in the first block while Elsie lives in the nn-th one. They have a map of the farm
which shows that it takes they titi minutes to travel from a block in EiEi to another block
in EiEi where Ei (1≤i≤m)Ei (1≤i≤m) is a set of blocks. They want to know how soon they can meet each other
and which block should be chosen to have the meeting.
Input
The first line contains an integer T (1≤T≤6)T (1≤T≤6), the number of test cases. Then TT test cases
follow.
The first line of input contains nn and mm. 2≤n≤1052≤n≤105. The following mm lines describe the sets Ei (1≤i≤m)Ei (1≤i≤m). Each line will contain two integers ti(1≤ti≤109)ti(1≤ti≤109) and Si (Si>0)Si (Si>0) firstly. Then SiSi integer follows which are the labels of blocks in EiEi. It is guaranteed that ∑mi=1Si≤106∑i=1mSi≤106.
Output
For each test case, if they cannot have the meeting, then output “Evil John” (without quotes) in one line.
Otherwise, output two lines. The first line contains an integer, the time it takes for they to meet.
The second line contains the numbers of blocks where they meet. If there are multiple
optional blocks, output all of them in ascending order.
Sample Input
2
5 4
1 3 1 2 3
2 2 3 4
10 2 1 5
3 3 3 4 5
3 1
1 2 1 2
Sample Output
Case #1: 3
3 4
Case #2: Evil John
Hint
In the first case, it will take Bessie 1 minute travelling to the 3rd block, and it will take Elsie 3 minutes travelling to the 3rd block. It will take Bessie 3 minutes travelling to the 4th block, and it will take Elsie 3 minutes travelling to the 4th block. In the second case, it is impossible for them to meet.
建立中间点跑最短路
答案/2就可以了
#include<bits/stdc++.h>using namespace std;typedef long long ll;template <class T> inline void in(T &x) { T f = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1; x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; x *= f;}ll daon[1100005],daon2[1100005],dan[110000];int n,m,T,u=0,q,w,e;bool bj[1100005];vector<int>tu[1100005],fei[1100005];struct p{ int d,c; bool operator < (const p&a)const { return c>a.c; }};ll inf=0x3f3f3f3f3f3f3f3f;priority_queue<p>qq;main(){ in(T); while(T--) { in(n),in(m); memset(daon,0x3f,sizeof(daon)); memset(bj,0,sizeof(bj)); memset(daon2,0x3f,sizeof(daon2)); memset(dan,0,sizeof(dan)); for(int a=1;a<=n+m;a++)tu[a].clear(),fei[a].clear(); for(int a=1;a<=m;a++) { in(q),in(w); for(int b=1;b<=w;b++) { in(e); tu[n+a].push_back(e); tu[e].push_back(n+a); fei[n+a].push_back(q); fei[e].push_back(q); } } daon[1]=0; qq.push({1,0}); while(!qq.empty()) { p zs=qq.top(); qq.pop(); if(bj[zs.d])continue; bj[zs.d]=1; for(int a=0;a<tu[zs.d].size();a++) { if(bj[tu[zs.d][a]])continue; if(daon[tu[zs.d][a]]>daon[zs.d]+fei[zs.d][a]) { daon[tu[zs.d][a]]=daon[zs.d]+fei[zs.d][a]; qq.push({tu[zs.d][a],daon[tu[zs.d][a]]}); } } } memset(bj,0,sizeof(bj)); /*for(int a=1;a<=n;a++) { cout<<daon[a]<<" "; }// return 0;cout<<endl;*/ daon2[n]=0; qq.push({n,0}); while(!qq.empty()) { p zs=qq.top(); qq.pop(); if(bj[zs.d])continue; bj[zs.d]=1; for(int a=0;a<tu[zs.d].size();a++) { if(bj[tu[zs.d][a]])continue; if(daon2[tu[zs.d][a]]>daon2[zs.d]+fei[zs.d][a]) { daon2[tu[zs.d][a]]=daon2[zs.d]+fei[zs.d][a]; qq.push({tu[zs.d][a],daon2[tu[zs.d][a]]}); } } }/* for(int a=1;a<=n;a++) { cout<<daon2[a]<<" "; } return 0;*/ ll zdl=inf; for(int a=1;a<=n;a++) { if(daon[a]==inf||daon2[a]==inf)continue; zdl=min(zdl,max(daon[a],daon2[a])); } for(int a=1;a<=n;a++) { if(daon[a]==inf||daon2[a]==inf)continue; if(zdl!=max(daon[a],daon2[a]))continue; dan[++dan[0]]=a; } if(zdl==inf) { printf("Case #%d: Evil John\n",++u); continue; } printf("Case #%d: %lld\n",++u,zdl/2); int jc=0; for(int a=1;a<=dan[0];a++) { if(jc) { printf(" %d",dan[a]); continue; } jc=1; printf("%d",dan[a]); } printf("\n"); }}
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- git分支原理
- HDU2503-a/b + c/d
- Unity_杂项_访问修饰符在Unity监控面板的表现_050
- Linux下批量kill多个进程的方法
- 题目描述 有这样一道智力题:“某商店规定:三个空汽水瓶可以换一瓶汽水。小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?”答案是5瓶,方法如下:先用9个空瓶子换3瓶汽水,喝掉3瓶满的,喝完以后4个空
- HDU
- Burp Suite扫描器漏洞扫描功能介绍及简单教程
- WUST OJ 2057: 第K大子串和
- Mybatis配置文件优化
- java的取整函数
- luogu1280 尼克的任务(dp)
- HDU
- HDU 1060 Leftmost Digit
- webpack的使用(4) ---- 配置文件详解