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,然后还有奖金,然后员工之间有矛盾,有的员工希望比某员 ...
随机推荐
- 【Python入门总结】
用了两周时间将python的基本语法和模块过了一遍,alex的视频也简单看了下;并且在项目中直接上了python解析语义的实现,初步感觉到了python语言的魅力.下一步,会按照廖雪峰的python学 ...
- Linux下的计算器(bc、expr、dc、echo、awk)知多少?
linux 其他知识目录 原文链接:http://blog.chinaunix.net/uid-24673811-id-1760837.html linux下的三个命令可以用来作计算,下面一一讲解用法 ...
- javascript中的取反再取反~~
操作符~, 是按位取反的意思,表面上~~(取反再取反)没有意义,实际上在JS中可以将浮点数变成整数. <html> <script> var myArray = new Arr ...
- JS数据结构学习之排序
在看<>这本书中关于排序这一章的时候,我试着用javascript语言来重写里面几个经典的排序方法,包括冒泡排序.快速排序.选择排序.插入排序还有希尔排序. 一.冒泡排序 冒泡排序算是排序 ...
- Scrum立会报告+燃尽图(Beta阶段第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://coding.net/u/wuyy694 ...
- Opendarlight Carbon 安装
写在前面 目前最轻松的一次安装过程,感谢大翔哥的帮助. 安装过程 1.Zip包下载 找到Opendaylight官网,进入下载界面找到Carbon版本并下载. 2.Zip包解压 把这个zip压缩包解压 ...
- fast-IO
代码: int Scan() //输入外挂 { ,ch,flag=; if((ch=getchar())=='-') flag=; ') res=ch-'; ') res=res*+ch-'; ret ...
- 解析DXF图形文件格式
一.DXF文件格式分析 DXF文件由标题段.表段.块段.实体段和文件结束段5部分组成,其内容如下. ☆标题段(HEADER)标题段记录AutoCAD系统的所有标题变量的当前值或当前状态.标题变量记录了 ...
- erlang转化中文为url
今天使用http get 方法时,参量中有中文而导致出错. 例如http://abc.com/abc?arg=中文,在erlang使用http:request方法失败. 后来查了url的规范,url中 ...
- 1104 文法产生这段C程序的推导过程