Meeting HDU - 5521 虚点建图
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.
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.
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.
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
3 4
Case #2: Evil John
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.
#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 虚点建图的更多相关文章
- 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轮的策略不一 ...
- HDU 4292 Food (建图思维 + 最大流)
(点击此处查看原题) 题目分析 题意:某个餐馆出售f种食物,d种饮料,其中,第i种食物有fi份,第i种饮料有di份:此时有n个人来餐馆吃饭,这n个人必须有一份食物和一份饮料才会留下来吃饭,否则,他将离 ...
- 逃生 HDU 4857(反向建图 + 拓扑排序)
逃生 链接 Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必 ...
- hdu 4568 Hunter bfs建图+TSP状压DP
想AC的人请跳过这一段... 题目应该都能读懂.但是个人觉得这题出的很烂,意思太模糊了. 首先,进出次数只能是一次!!这个居然在题目中没有明确说明,让我在当时看到题目的时候无从下手. 因为我想到了这几 ...
- HDU 5521 [图论][最短路][建图灵感]
/* 思前想后 还是决定坚持写博客吧... 题意: n个点,m个集合.每个集合里边的点是联通的且任意两点之间有一条dis[i]的边(每个集合一个dis[i]) 求同时从第1个点和第n个点出发的两个人相 ...
- HDU 5521 Meeting(虚拟节点+最短路)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
- hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)
Walk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- Food HDU - 4292 网络流 拆点建图
http://acm.hdu.edu.cn/showproblem.php?pid=4292 给一些人想要的食物和饮料,和你拥有的数量,问最多多少人可以同时获得一份食物和一份饮料 写的时候一共用了2种 ...
- hdu 2647 (拓扑排序 邻接表建图的模板) Reward
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2647 老板给员工发工资,每个人的基本工资都是888,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员 ...
随机推荐
- PHPCMS V9 的手机门户wap绑定单页面
当前的Phpcms V9手机网站的设置还有点弱,绑定的栏目不能设置选择模板,而且不能绑定单页面page.不过可以自定义做到绑定单页面page这一个功能:1.修改phpcms\modules\wap\i ...
- [朴孝敏][Gold]
歌词来源:http://music.163.com/#/song?id=406924220 作曲 : Ryan S. Jhun/David Quinones/Edwin Menjivar/Mateo ...
- 初创型公司如何经济有效的申请邓白氏编码(DUNS)
听说有免费,和800元,1500元,上万元等不同的申请方式?听说申请完还要等十数个工作日让邓白氏和苹果的数据库同步.不同高低价格的申请方式得到的编码都能被苹果接受吗? http://www.zhihu ...
- Java:重写equals()和hashCode()
Java:重写equals()和hashCode() 1.何时需要重写equals() 当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念). 2.设计equals() [1]使用instan ...
- wireshark解析https协议方法
本文仅介绍通过协商密钥的方式实现https解析的方法 wireshark支持pem
- scrum立会报告+燃尽图(第三周第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://coding.net/u/wuyy694 ...
- 20181023-10 Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 07
作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2290 Scrum master:范靖旋 一.小组介绍 组长:王一可 组员: ...
- 王者荣耀交流协会final发布中间产物
WBS+PSP 版本控制报告 软件功能说明书final修订
- yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。
CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 $ wget http://repo.mysql.com ...
- selenium webdriver 表格的定位方法练习
selenium webdriver 表格的定位方法 html 数据准备 <html> <body> <div id="div1"> <i ...