Meeting

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 6865    Accepted Submission(s): 2085

Problem Description
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 n blocks labelled from 1 to n.
Bessie lives in the first block while Elsie lives in the n-th one. They have a map of the farm
which shows that it takes they ti minutes to travel from a block in Ei to another block
in Ei where 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), the number of test cases. Then T test cases
follow.

The first line of input contains n and m. 2≤n≤105. The following m lines describe the sets Ei (1≤i≤m). Each line will contain two integers ti(1≤ti≤109)and Si (Si>0) firstly. Then Si integer follows which are the labels of blocks in Ei. It is guaranteed that ∑mi=1Si≤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.

 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  6730 6729 6728 6727 6726 
 
 /*************************************************************************
> File Name: meeting.cpp
> Author: CruelKing
> Mail: 2016586625@qq.com
> Created Time: 2019年09月21日 星期六 11时26分48秒
本题思路:用Dijkstra结果wa了,很无奈,换了spfa就过了,哦,不是就过了,是
各种TLE,WA,PE都不提示,给别人提示的是WA,时段不同也能T.搞心态的题......
就是个傻逼题:稍加分析就知道一个块内全部建边是不可行的,对每个块建立一个超级
源点,块内的点向超级源点连一条边,跑一波最短路,后续细节处理很简单.傻逼题.
************************************************************************/ #include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std; const int maxn = + , maxm = + ; typedef long long ll; ll inf = LLONG_MAX; struct Edge {
int to, cost, next;
} edge[maxm << ]; int head[maxn], tot; int n, m; ll diss[maxn], dist[maxn]; ll dis[maxn]; bool vis[maxn]; void init() {
memset(head, -,sizeof head);
tot = ;
} void addedge(int u, int v, int w) {
edge[tot].to = v; edge[tot].cost = w; edge[tot].next = head[u]; head[u] = tot ++;
edge[tot].to = u; edge[tot].cost = w; edge[tot].next = head[v]; head[v] = tot ++;
} void dijkstra(int s, ll (&_dis)[maxn]) {
memset(vis, false, sizeof vis);
for(int i = ; i <= m + n; i ++) _dis[i] = inf;
_dis[s] = ;
vis[s] = true;
queue <ll> que;
que.push(s);
while(!que.empty()) {
int u = que.front(); que.pop(); vis[u] = false;
for(int i = head[u]; ~i; i = edge[i].next) {
int v = edge[i].to;
if(_dis[v] > _dis[u] + edge[i].cost) {
_dis[v] = _dis[u] + edge[i].cost;
if(!vis[v]) {
vis[v] = true;
que.push(v);
}
}
}
}
} int ans[maxn], cnt; int main() {
int t, v, w, num, _case = ;
scanf("%d", &t);
while(t --) {
cnt = ;
init();
// memset(dis, inf ,sizeof dis);
scanf("%d %d", &n, &m);
for(int i = ; i <= n + m; i ++) dis[i] = inf;
for(int u = ; u <= m; u ++) {
scanf("%d %d", &w, &num);
while(num --) {
scanf("%d", &v);
addedge(u, m + v, w);
}
}
dijkstra( + m, diss);
dijkstra(n + m, dist);
ll Min = inf;
for(int i = + m; i <= n + m; i ++) {
if(diss[i] < inf && dist[i] < inf) {
dis[i] = max(diss[i], dist[i]);
if(dis[i] < Min) Min = dis[i];
}
}
printf("Case #%d: ", ++ _case);
if(Min != inf) {
printf("%lld\n", Min / );
for(int i = + m; i <= n + m; i ++) {
if(dis[i] == Min) {
ans[cnt ++] = i - m;
}
}
for(int i = ; i < cnt; i ++) {
if(i) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
} else printf("Evil John\n");
}
return ;
}

2015沈阳区域赛Meeting(最短路 + 建图)的更多相关文章

  1. 第八届河南省赛C.最少换乘(最短路建图)

    C.最少换乘 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 94  Solved: 25 [Submit][Status][Web Board] De ...

  2. 2017 ICPC/ACM 沈阳区域赛HDU6223

    Infinite Fraction Path Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java ...

  3. HDU5521-最短路-建图

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  4. HDU 5521 [图论][最短路][建图灵感]

    /* 思前想后 还是决定坚持写博客吧... 题意: n个点,m个集合.每个集合里边的点是联通的且任意两点之间有一条dis[i]的边(每个集合一个dis[i]) 求同时从第1个点和第n个点出发的两个人相 ...

  5. hdu4725 The Shortest Path in Nya Graph【最短路+建图】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4297574.html      ---by 墨染之樱花 题目链接:http://acm.hdu ...

  6. Codeforces 938D. Buy a Ticket (最短路+建图)

    <题目链接> 题目大意: 有n座城市,每一个城市都有一个听演唱会的价格,这n座城市由m条无向边连接,每天变都有其对应的边权.现在要求出每个城市的人,看一场演唱会的最小价值(总共花费的价值= ...

  7. hdu 5294 Tricks Device 最短路建图+最小割

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Tricks Device Time Limit: 2000/1000 MS (Java/Other ...

  8. hdu 4725 The Shortest Path in Nya Graph (最短路+建图)

    The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. 『The Captain 最短路建图优化』

    The Captain(BZOJ 4152) Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小 ...

随机推荐

  1. python_多线程多进程

    多线程,适用于IO密集型任务 IO,input,output缩写,包括网路io(比如上传下载),磁盘io,(比如数据库读写),CPU操作不频繁 多进程,适用于CPU密集型任务 数据分析,算法,依赖CP ...

  2. pdf转换

    namespace Utilities { public static class PDFHelper { /// <summary> /// Html转Pdf /// </summ ...

  3. “M_PI_2”: 重复定义的宏

    问题警告:“M_PI_2”: 重复定义的宏 分析:在Visual Studio上使用math.h库时与其他库数学库冲突,我们可以通过添加宏定义“_USE_MATH_DEFINES”来消除math.h定 ...

  4. head first 设计模式笔记1-策略模式:模拟鸭子

    1.第一个设计原则:找出应用中可能需要变化之处,把它们独立出来,不要和那些不需要变化的代码混在一起.该原则几乎是所有设计模式背后的精神所在. 这个原则的另一种思考方式:把会变化的部分取出并封装起来,以 ...

  5. c语言 - 关键字const的作用

    const修饰的数据类型是指常类型,常类型的变量或对象的值是不能被更新的. 1.const char * p1;              //表示p1指向了的字符串不可更改 2.char const ...

  6. javascript中创建对象的方式及优缺点(一)

    1. 简单方式创建对象 // 字面量方式创建对象 var person1 = { name: "xyc", age: 23, sayHi: function() { console ...

  7. 我不熟悉的list

    其实在日常中,链表的题目做的比较多,但是使用STL自带链表的还是比较少,所以里面的一些API不大熟悉.这边也简要介绍一些. 基本的一些API 先列举的这些和上面几篇用法几乎一样,所以不再累述. 赋值相 ...

  8. 分区间统计sql、删除重复数据

    删除重复数据 备份表 删除最早的评论

  9. POJ 6621: K-th Closest Distance(主席树 + 二分)

    K-th Closest Distance Time Limit: 20000/15000 MS (Java/Others)    Memory Limit: 524288/524288 K (Jav ...

  10. MDK Keil 5软件小技巧

    几乎所有玩ARM Cortex M单片机的坛友都是通过MDK Keil 5或者IAR环境进行单片机的程序开发的,俗话说工欲善其事必先利其器,我们天天都在用这个开发环境,那么,有些在MDK Keil 5 ...