hdu-5521 Meeting(最短路)
题目链接:
Meeting
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2024 Accepted Submission(s): 628
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define lson o<<1
#define rson o<<1|1
typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e6+10;
const int maxn=2e6+5;
const double eps=1e-12; int n,m,cnt,s,e,vis[maxn],c[maxn],head[maxn];
LL dis[2][maxn];
struct Edge
{
int to,next,val;
}edge[maxn];
queue<int>qu;
inline void add_edge(int from,int to,int va)
{
edge[cnt].to=to;
edge[cnt].next=head[from];
edge[cnt].val=va;
head[from]=cnt++;
} void solve(int s,int e,int f)
{
while(!qu.empty())qu.pop();
mst(vis,0);
for(int i=0;i<maxn;i++)dis[f][i]=inf;
dis[f][s]=0;
qu.push(s);
vis[s]=1;
while(!qu.empty())
{
int fr=qu.front();qu.pop();
for(int i=head[fr];i!=-1;i=edge[i].next)
{
int x=edge[i].to;
if(dis[f][x]>dis[f][fr]+edge[i].val)
{
dis[f][x]=dis[f][fr]+edge[i].val;
if(!vis[x])qu.push(x),vis[x]=1;
}
}
vis[fr]=0;
}
}
int main()
{
int t,Case=0;
read(t);
while(t--)
{
printf("Case #%d: ",++Case);
mst(head,-1);
cnt=0;
read(n);read(m);
int x,h,t;
for(int i=1;i<=m;i++)
{
read(t);read(h);
for(int j=1;j<=h;j++)
{
read(x);
add_edge(x,n+i,t);
add_edge(n+i,x,t);
}
}
solve(1,n,0);
solve(n,1,1);
LL ans=inf;
for(int i=1;i<=n;i++)ans=min(ans,max(dis[0][i],dis[1][i]));
if(ans==inf)printf("Evil John\n");
else
{
printf("%lld\n",ans/2);
int num=0;
for(int i=1;i<=n;i++)if(max(dis[0][i],dis[1][i])==ans)c[++num]=i;
for(int i=1;i<num;i++)printf("%d ",c[i]);
printf("%d\n",c[num]);
}
}
return 0;
}
hdu-5521 Meeting(最短路)的更多相关文章
- HDU 5521.Meeting 最短路模板题
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU 5521 Meeting(虚拟节点+最短路)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
- hdu 5521 Meeting(最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题意:有1-n共n个点,给出m个块(完全图),并知道块内各点之间互相到达花费时间均为ti.已知两 ...
- HDU 5521 Meeting【最短路】
今天旁观了Angry_Newbie的模拟区域赛(2015shenyang) 倒着看最先看的M题,很明显的最短路问题,在我看懂的时候他们已经开始敲B了. 后来听说D过了很多人.. D题一看是个博弈,给了 ...
- HDU 5521 Meeting (最短路,dijstra)
题意:有N个点,两个人,其中一个人住在点1,另一个人住在点n,有M个点集,集合内的数表示任意两点的距离为dis ,现在问,如果两个人要见面, 需要最短距离是多少,有哪几个点能被当成见面点. 析:分别对 ...
- HDU 5521 [图论][最短路][建图灵感]
/* 思前想后 还是决定坚持写博客吧... 题意: n个点,m个集合.每个集合里边的点是联通的且任意两点之间有一条dis[i]的边(每个集合一个dis[i]) 求同时从第1个点和第n个点出发的两个人相 ...
- HDU 5521 Meeting
2015 ACM / ICPC 沈阳站现场赛 M题 最短路 设置N+M个节点,前N个节点是Block,后M个节点是Set,每一组Set中的点向该Set连边,从1和n开始分别求最短路.注意爆int. # ...
- HDU - 5521 Meeting (Dijkstra)
思路: 看了好久才看懂题意,文中给了n个点,有m个集合,每个集合有s个点,集合内的每两个点之间有一个权值为t的边,现在有两个人,要从1号点,和n号点,走到同一个顶点,问最少花费以及花费最少的点. 那就 ...
- HDU 5521:Meeting(最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=5521 Meeting Problem Description Bessie and her friend E ...
- hdu 5521 最短路
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
随机推荐
- 搭建spring的开发环境
在eclipse中新建web项目,集成spring开发环境,把集成spring的过程描述如下, 1.从spring官网下载spring的jar包,我这里是spring4.1,下载的文件中包含了源码及文 ...
- 测试驱动开发(TDD)的思考
极限编程 敏捷开发是一种思想,极限编程也是一种思想,它与敏捷开发某些目标是一致的.只是实现方式不同.测试驱动开发是极限编程的一部分. 1.极限编程这个思路的来源 Kent Beck先生最早在其极限编程 ...
- CSS布局——居中
参考文章1.CSS布局奇淫技巧之--各种居中 2.http://www.imooc.com/article/2235 1.行内元素水平居中text-align:center对图片,按钮,文字等行内元素 ...
- ECMAScript 6学习笔记(二):let和块级作用域
同步发布于:https://mingjiezhang.github.io/(转载请说明此出处). ES6中加入了let,也让JavaScript拥有了块级作用域. 没有块级作用域的JavaScript ...
- 深入了解Activity-生命周期
一 介绍 Activity是android中使用最为频繁的组件,在官方文档中是这样描述的:An activity is a single, focused thing that the user ca ...
- Python学习二---字符串
一.字符串 1.1.字符串和转义字符 转义字符需要使用\来表示 1.2.字符串连接 print 字符串1 字符串2,打印出来的字符串直接连接在一起没有空格 print 字符串1,字符串2,打印出来的字 ...
- 比较好用的web打印控件——Lodop
前一段时间公司一项目比较特殊,客户要求打印单必须是淘宝上卖的那种三联打印单.如果还是使用原来系统自带的打印的话,就会造成无法打印出来理想的效果,于是找了下相关的打印控件,比较网络上比较流行的几款插件, ...
- 深入理解CSS中的层叠上下文和层叠顺序
零.世间的道理都是想通的 在这个世界上,凡事都有个先后顺序,凡物都有个论资排辈.比方说食堂排队打饭,对吧,讲求先到先得,总不可能一拥而上.再比如说话语权,老婆的话永远是对的,领导的话永远是对的. 在C ...
- 关于git
一.Git基础教程 01.[入门练习]廖雪峰 git教程网:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8 ...
- CTF中那些脑洞大开的编码和加密
0x00 前言 正文开始之前先闲扯几句吧,玩CTF的小伙伴也许会遇到类似这样的问题:表哥,你知道这是什么加密吗?其实CTF中脑洞密码题(非现代加密方式)一般都是各种古典密码的变形,一般出题者会对密文进 ...