Appoint description: 
System Crawler  (2016-04-18)

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 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> blocks
labelled from 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> to 
Bessie lives in the first block while Elsie lives in the -th
one. They have a map of the farm 
which shows that it takes they  minutes
to travel from a block in  to
another block 
in  where 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" /> 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 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.111em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.111em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-5px;display:inline !important;float:none !important;" />,
the number of test cases. Then 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.111em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> test
cases 
follow. 

The first line of input contains  and 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />.
The following  lines
describe the sets 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .288em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />.
Each line will contain two integers 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> and 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px -.054em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" /> firstly.
Then  integer
follows which are the labels of blocks in .
It is guaranteed that 

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .003em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .117em 0px 0px;min-width:0px;min-height:0px;vertical-align:-3px;display:inline !important;float:none !important;" />

rev=2.4-beta-2" alt="" style="border:0px;padding:0px;margin:0px .06em 0px 0px;min-width:0px;min-height:0px;vertical-align:0px;display:inline !important;float:none !important;" />.

 

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.
         
 

题意 

   有 N个点 n<=100000 ,m《=10000个集合。在同一个集合中的人意两个点的距离都相等,不同的集合时间不一定同样。 一个人从1 出发,一个人从n出发求 二人相遇的最时间

 思路:

  假设按普通的写法 则须要建立非常多的边。边太多是存不下的,所以要缩图,缩图的方法 

  

这样就能够了 。保证了集合内的点人意点都是time  哈

  可是 使用普通的SPFA  就会超时!!QAQ 

    须要是用 dijktra + 优先队列  

   套了个最短路优化模版 就能够了

#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
using namespace std;
const int N = 1000100*2;
const long long INF = 1e18;
int n, m;
long long dis[N];
long long dis1[N];
long long dis2[N];
long long f[N];
bool vis[N];
struct Node
{
long long d;
int e;
bool operator < (const Node x) const
{
return x.d < d;
}
Node(long long d, int e):d(d), e(e) {}
};
vector<pair<int,long long > > V[N];
void dijkstra(int s)
{
priority_queue<Node> q;
fill(dis + 1, dis + n+2*m + 1, INF);
fill(vis + 1, vis + n+2*m + 1, false);
q.push(Node(0, s));
dis[s] = 0;
while(!q.empty())
{
Node deq = q.top();
q.pop();
if(vis[deq.e])
continue;
vis[deq.e] = true;
for(int i = 0; i < sz(V[deq.e]); i++)
{
int e = V[deq.e][i].first;
long long w = V[deq.e][i].second;
if(dis[deq.e] < dis[e] - w)
{
dis[e] = dis[deq.e] + w;
q.push(Node(dis[e], e));
}
}
}
}
void add_edge(int a,int b,long long c)
{
V[a].push_back(make_pair(b, c));
}
long long max(long long a,long long b)
{
if(a>b)
return a;
return b;
}
long long min(long long a,long long b)
{
if(a>b)return b;
return a;
}
int main()
{
int T;
scanf("%d",&T);
int CASE=1 ;
while(T--)
{
scanf("%d%d",&n,&m);
int fc = n+1;
for(int i = 1; i<=n+m*2+1; i++)
V[i].clear();
long long time ;
int y;
for(int i = 1; i<=m; i++)
{
scanf("%lld%d",&time,&y);
int temp ;
for(int j = 1; j<=y; j++)
{
scanf("%d",&temp);
add_edge(temp,fc,0);
add_edge(fc+1,temp,0);
}
add_edge(fc,fc+1,time);
fc+=2;
} dijkstra(1);
memcpy(dis1,dis,sizeof(dis));
dijkstra(n);
memcpy(dis2,dis,sizeof(dis)); long long minv = INF;
for(int i =1 ; i<=n; i++)
{
f[i] = max(dis1[i],dis2[i]);
minv = min(minv,f[i]);
}
printf("Case #%d: ",CASE++);
if(minv>=INF)
{
printf("Evil John\n");
}
else
{
printf("%lld\n",minv); int flagc = 0;
for(int i = 1; i<=n; i++)
{
if(f[i]==minv)
{
if(!flagc)
{
printf("%d",i);
flagc = 1;
}
else
printf(" %d",i);
}
}
printf("\n");
}
}
return 0;
}

    

2015 ICPC 沈阳站M题的更多相关文章

  1. 2016 ICPC青岛站---k题 Finding Hotels(K-D树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5992 Problem Description There are N hotels all over ...

  2. 2015 ACM-ICPC 沈阳站

    题目链接  2015 ACM-ICPC Shenyang Problem A Problem B Problem C Problem D 签到题,所有gcd的倍数都可以被写出来. 那么判断一下这类数的 ...

  3. 2016 ACM/ICPC 沈阳站 小结

    铜铜铜…… 人呐真奇怪 铁牌水平总想着运气好拿个铜 铜牌水平总想着运气好拿个银 估计银牌的聚聚们一定也不满意 想拿个金吧 这次比赛挺不爽的 AB两道SB题,十分钟基本全场都过了 不知道出这种题有什么意 ...

  4. 2020ICPC沈阳站C题 Mean Streets of Gadgetzan

    大致题意 原题链接 翻译 \(有n个逻辑变量 请你分别对它们赋值 使其满足m个命题\) \(命题有四种格式:\) 单独数字x 表示第x个逻辑变量为真 ! + 数字x 表示第x个逻辑变量为假 若干个数字 ...

  5. 2020 ICPC 沈阳站 I - Rise of Shadows 题解

    题面看这里 \(PS\):符号 \([\ \rm P\ ]\) 的意义是:当表达式 \(\rm P\) 为真则取值为 \(1\),为假则取值为 \(0\). 题目大意 给你一个一天有 \(H\)​​​ ...

  6. 2016 ICPC大连站---F题 Detachment

    题意:输入一个x,将x拆分成一些小的数(这些数不能相同,即x=a1+a2+......   ai!=aj when i!=j),然后这些数相乘得到一个成积(s=a1*a2*......),求最大的乘积 ...

  7. HDU 5950Recursive sequence ICPC沈阳站

    Recursive sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  8. 2016ACM/ICPC亚洲区沈阳站-重现赛赛题

    今天做的沈阳站重现赛,自己还是太水,只做出两道签到题,另外两道看懂题意了,但是也没能做出来. 1. Thickest Burger Time Limit: 2000/1000 MS (Java/Oth ...

  9. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

随机推荐

  1. 北邮校赛 I. Beautiful Array(DP)

    I. Beautiful Array 2017- BUPT Collegiate Programming Contest - sync 时间限制 1000 ms 内存限制 65536 KB 题目描述 ...

  2. D - Matrix Multiplication ZOJ - 2316 规律题

    Let us consider undirected graph G = which has N vertices and M edges. Incidence matrix of this grap ...

  3. SQLSEVER 中的那些键和约束

    SQL Server中有五种约束类型,分别是 PRIMARY KEY约束.FOREIGN KEY约束.UNIQUE约束.DEFAULT约束.和CHECK约束.查看或者创建约束都要使用到 Microso ...

  4. Codeforces Round #114 (Div. 1) C. Wizards and Numbers 博弈论

    C. Wizards and Numbers 题目连接: http://codeforces.com/problemset/problem/167/C Description In some coun ...

  5. Alpha冲刺(6/10)——追光的人

    1.队友信息 队员学号 队员博客 221600219 小墨 https://www.cnblogs.com/hengyumo/ 221600240 真·大能猫 https://www.cnblogs. ...

  6. 动态扩展php组件(mbstring为例)

    1.进入源码包中的mbstring目录 cd ~/php-/ext/mbstring/ 2.启动phpize /usr/local/php/bin/phpize 3.配置configure ./con ...

  7. Mac下的MySQL修改默认连接字符集

    进入命令行执行以下命令: sudo vim /etc/my.cnf [client] default-character-set=utf8 [mysqld] character-set-server= ...

  8. iOS UIPrintInteractionController打印

    - (void)printData{ //为打印做准备,创建一个指向sharedPrintController的引用 UIPrintInteractionController *printer = [ ...

  9. dns问题,QQ打得开,网页打不开

    dns问题,QQ打得开,网页打不开 ip4 dns 改为114.114.114.114. 原因有可能是路由出错之类的.114是默认的通用ip

  10. Java_导出Excel

    导出的Excel标题.Sheet名称.数据内容都可以使用中文​ 一.pom.xml引入jar包 1 2 3 4 5 <dependency>             <groupId ...