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.

 
 
巧妙的建图 
题意:
       两个人分别在1和n区。给出区之间有联系的图以及到达所需时间。
      求两个人见面最短时间以及在哪个区碰面(可有多个)
 
巧妙的建图,对于每一个集合里面的点都连向一个虚点,
每一条边的权值为都为tt 最后除以2就好了。
然后分别从1和n跑一遍最短路
minn = min ( minn, max ( d[i][0], d[i][1] ) );
 
 #include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define rtl rt<<1
#define rtr rt<<1|1
#define bug printf("******\n")
#define mem(a,b) memset(a,b,sizeof(a))
#define name2str(x) #x
#define fuck(x) cout<<#x" = "<<x<<endl
#define f(a) a*a
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define pf printf
#define FRE(i,a,b) for(i = a; i <= b; i++)
#define FREE(i,a,b) for(i = a; i >= b; i--)
#define FRL(i,a,b) for(i = a; i < b; i++)
#define FRLL(i,a,b) for(i = a; i > b; i--)
#define FIN freopen("in.txt","r",stdin)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 0x7fffffff;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const int maxn = 3e6 + ;
int t, n, m, tot, head[maxn], vis[maxn];
LL d[maxn][];
struct Edge {
int v, nxt;
LL w;
} edge[maxn * ];
void init() {
tot = ;
mem ( head, - );
}
void add ( int u, int v, LL w ) {
edge[tot].v = v;
edge[tot].w = w;
edge[tot].nxt = head[u];
head[u] = tot++;
}
struct node {
LL d, v;
node ( LL d, LL v ) : d ( d ), v ( v ) {}
bool operator < ( const node & a ) const {
return d > a.d;
}
};
void dijstar ( int flag ) {
priority_queue<node>q;
int s = flag ? n : ;
for ( int i = ; i <= n + m ; i++ ) d[i][flag] = INFLL, vis[i] = ;
d[s][flag] = ;
q.push ( node ( , s ) );
while ( !q.empty() ) {
node temp = q.top();
q.pop();
int u = temp.v;
if ( vis[u] ) continue;
vis[u] = ;
for ( int i = head[u]; ~i ; i = edge[i].nxt ) {
int v = edge[i].v;
if ( d[v][flag] > d[u][flag] + edge[i].w && !vis[v] ) {
d[v][flag] = d[u][flag] + edge[i].w;
q.push ( node ( d[v][flag], v ) );
}
}
}
}
int main() {
sf ( t );
int cas = ;
while ( t-- ) {
sff ( n, m );
init();
int p = n;
for ( int i = , s, v, x ; i < m ; i++ ) {
p++;
LL tt;
scanf ( "%lld%d", &tt, &s );
while ( s-- ) {
sf ( x );
add ( p, x, tt );
add ( x, p, tt );
}
}
dijstar ( );
dijstar ( );
LL minn = INFLL;
vector<int>ans;
for ( int i = ; i <= n ; i++ ) minn = min ( minn, max ( d[i][], d[i][] ) );
if ( minn == INFLL ) printf ( "Case #%d: Evil John\n", cas++ );
else {
ans.clear();
printf ( "Case #%d: %lld\n", cas++, minn / );
for ( int i = ; i <= n ; i++ )
if ( max ( d[i][], d[i][] ) == minn ) ans.push_back ( i );
for ( int i = ; i < ans.size(); i++ ) printf ( "%d%c", ans[i], i == ans.size() - ? '\n' : ' ' );
}
}
return ;
}

Meeting HDU - 5521 虚点建图的更多相关文章

  1. Eliminate the Conflict HDU - 4115(2-sat 建图 hhh)

    题意: 石头剪刀布 分别为1.2.3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一 ...

  2. HDU 4292 Food (建图思维 + 最大流)

    (点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...

  3. 逃生 HDU 4857(反向建图 + 拓扑排序)

    逃生 链接 Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必 ...

  4. hdu 4568 Hunter bfs建图+TSP状压DP

    想AC的人请跳过这一段... 题目应该都能读懂.但是个人觉得这题出的很烂,意思太模糊了. 首先,进出次数只能是一次!!这个居然在题目中没有明确说明,让我在当时看到题目的时候无从下手. 因为我想到了这几 ...

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

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

  6. HDU 5521 Meeting(虚拟节点+最短路)

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

  7. hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)

    Walk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  8. Food HDU - 4292 网络流 拆点建图

    http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...

  9. hdu 2647 (拓扑排序 邻接表建图的模板) Reward

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2647 老板给员工发工资,每个人的基本工资都是888,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员 ...

随机推荐

  1. 7.hdfs工作流程及机制

    1. hdfs基本工作流程 1. hdfs初始化目录结构 hdfs namenode -format 只是初始化了namenode的工作目录 而datanode的工作目录是在datanode启动后自己 ...

  2. 20181120-6 Beta阶段第2周/共2周 Scrum立会报告+燃尽图 03

    此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制地址    [https://git.coding.n ...

  3. Scrum立会报告+燃尽图(06)选题

    此作业要求参见:[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2195] 一.小组介绍 组长:王一可 组员:范靖旋,王硕,赵佳璐,范洪达 ...

  4. Thunder团队第七周 - Scrum会议2

    Scrum会议2 小组名称:Thunder 项目名称:i阅app Scrum Master:王航 工作照片: 参会成员: 王航(Master):http://www.cnblogs.com/wangh ...

  5. Thunder团队第七周 - Scrum会议1

    Scrum会议1 小组名称:Thunder 项目名称:i阅app Scrum Master:杨梓瑞 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...

  6. short数组写进txt

    short[] ssss=new short[gaoDeData.Length]; FileStream fs = new FileStream("E:\\123.txt", Fi ...

  7. 使用java中的注解@see

    缘起 在写java时,有时需要写注释,而为了更好的描述,需要引用和参考其他代码.为了让阅读者更好的体验,javadoc中支持链接跳转,这就需要用到注解@see. @see用法 注解@see可以在注释中 ...

  8. UML之Enterprise Architect使用

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:UML之Enterprise Architect使用     本文地址:http://tech ...

  9. crontab部署定时任务

    1.安装cron工具:apt-getinstall cron 2.开启定时任务:crontab –e 定时任务语句格式为:执行周期+命令. 周期有5个域,分别是分,时,日(day of month), ...

  10. Cobbler环境搭建

    Cobbler服务器系统: CentOS 6.6 64位Cobbler版本: cobbler-2.6.11IP地址:192.168.166.136 1.安装epel库 rpm -ivh http:// ...