传送门

题目

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 casesfollow.
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 multipleoptional blocks, output all of them in ascending order.

题目大意

现在给出一个图,其中分成点分成一个集合一个集合的,每一集合中的点互相之间的距离都是相同的,也给出来了;现在要求两个人分别从1和n出发,问最短多长时间才能遇到,且给出这些可能的相遇点;

分析

这个题主要在构图,思路比较好想。将所有点和它所属的集合依次连边,原本的点无点权,集合所代表的点权即为每一集合中的点互相之间的距离。然后以第1个点和第n个点分别为起点计算出点权最短路即可,最终每点的相遇所需时间即为两次计算的值中较大的那一个。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
vector<int>v[];
priority_queue<pair<int,int> >q;
int vis[],d1[],d2[],val[];
int ans[];
int main()
{ int n,m,i,j,k,t,p,s,x;
scanf("%d",&t);
for(p=;p<=t;p++){
scanf("%d%d",&n,&m);
for(i=;i<=n+m;i++)v[i].clear();
memset(vis,,sizeof(vis));
memset(d1,0x3f,sizeof(d1));
memset(d2,0x3f,sizeof(d2));
memset(val,,sizeof(val));
for(i=;i<=m;i++){
scanf("%d%d",&val[i+n],&s);
for(j=;j<=s;j++){
scanf("%d",&x);
v[x].push_back(i+n);
v[i+n].push_back(x);
}
}
d1[]=;
q.push(make_pair(,));
while(!q.empty()){
x=q.top().second;
q.pop();
if(vis[x])continue;
vis[x]=;
for(i=;i<v[x].size();i++){
int y=v[x][i];
if(d1[x]+val[y]<d1[y]){
d1[y]=d1[x]+val[y];
q.push(make_pair(-d1[y],y));
}
}
}
memset(vis,,sizeof(vis));
d2[n]=;
q.push(make_pair(,n));
while(!q.empty()){
x=q.top().second;
q.pop();
if(vis[x])continue;
vis[x]=;
for(i=;i<v[x].size();i++){
int y=v[x][i];
if(d2[x]+val[y]<d2[y]){
d2[y]=d2[x]+val[y];
q.push(make_pair(-d2[y],y));
}
}
}
int pl,minn=0x3f3f3f3f;
for(i=;i<=n;i++)
if(max(d1[i],d2[i])<minn){
minn=max(d1[i],d2[i]);
pl=i;
}
int cnt=;
printf("Case #%d: ",p);
if(minn<0x3f3f3f3f){
printf("%d\n",minn);
for(i=;i<=n;i++)
if(max(d1[i],d2[i])==minn)
ans[++cnt]=i;
for(i=;i<cnt;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[cnt]);
}
else printf("Evil John\n");
}
return ;
}
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.

hdu5521 Meeting的更多相关文章

  1. HDU5521 Meeting(dijkstra+巧妙建图)

    HDU5521 Meeting 题意: 给你n个点,它们组成了m个团,第i个团内有si个点,且每个团内的点互相之间距离为ti,问如果同时从点1和点n出发,最短耗时多少相遇 很明显题目给出的是个无负环的 ...

  2. hdu-5521 Meeting(最短路)

    题目链接: Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  3. hdu5521(Meeting)spfa 层次网络最短路

    题意:给出几个集合,每个集合中有Si个点 且任意两个点的距离为ti,现在要求两个人分别从1和n出发,问最短多长时间才能遇到,且给出这些可能的相遇点; 取两个人到达某点时所用时间大的值 然后取最小的   ...

  4. ACM学习历程—HDU5521 Meeting(图论)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...

  5. HDU5521 Meeting 题解 最短路

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 题目大意: 有 \(n\) 个点 \(m\) 个集合,一个点可能处于若干个集合内,属于第 \(i ...

  6. [hdu5521 Meeting]最短路

    题意:有N个点,给定M个集合,集合Si里面的点两两之间的距离都为Ti,集合里面的所有点数之和<=1e6.有两个人分别在1和N处,求1个点使得两个人到这一点距离的最大值最小 思路:这题是裸的最短路 ...

  7. 「赛后补题」Meeting(HDU-5521)

    题意 A,B两个人分别在1和n区.每个区有若干点(区之间的点可以重复,各个区内点间的距离一致),给出区之间有联系的图以及到达所需时间.求两个人见面最短时间以及在哪个区碰面(可有多个) 分析 隐式图搜索 ...

  8. 【HDU5521】Meeting

    题目大意:给定一张\(N\)个点的图,构成了\(M\)个团,每个团内的边权均相等,求图上有多少个点满足到\(1\)号节点和\(N\)号节点的最大值最小. 题解: 本题的核心是如何优化连边,考虑对于每一 ...

  9. [LeetCode] Best Meeting Point 最佳开会地点

    A group of two or more people wants to meet and minimize the total travel distance. You are given a ...

随机推荐

  1. hdu1085 Holding Bin-Laden Captive!(母函数)

    简单的母函数应用. #include<iostream> #include<cstdio> #include<cstdlib> #include<cstrin ...

  2. bzoj 4299 Codechef FRBSUM

    定义一个集合的神秘数为不能表示成这个集合的某个子集和的最小正整数,给一个数列,多次求区间神秘数 $n \leq 100000$ sol: 考虑这个神秘数的性质,可以发现,如果神秘数是 $x$,那么 $ ...

  3. BZOJ - 3631 松鼠的新家 (树链剖分)

    题目链接 树链剖分基础题,路径权值修改+差分 #include<bits/stdc++.h> using namespace std; typedef long long ll; ; in ...

  4. UVA - 242 Stamps and Envelope Size (完全背包+bitset)

    题意:给你一些邮票面值的集合,让你选择其中一个集合,使得“能用不超过n枚集合中的邮票凑成的面值集合S中从1开始的最大连续面值”(即mex(S)-1)最大.如果有多解,输出集合大小最小的一个:如果仍有多 ...

  5. poj2374 Fence Obstacle Course[线段树+DP]

    https://vjudge.net/problem/POJ-2374 吐槽.在这题上面磕了许久..英文不好题面读错了qwq,写了个错的算法搞了很久..A掉之后瞥了一眼众多julao题解,**,怎么想 ...

  6. swing之UI选择文件

    package gui1; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEve ...

  7. LoadRunner常见错误代码解决方案

    一.LoadRunner26377错误 通常不是长度的问题,如果长度有问题就都出错了.应该是服务器返回的数据问题,导致没有找到这个参数. 26377错误的成因很多,总结最直接的结果就是No match ...

  8. BZOJ3141:[HNOI2013]旅行

    浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...

  9. 日志管理系统ELK6.2.3

    https://www.jianshu.com/p/88f2cbedcc2a 写在前面 刚毕业工作的时候,处理日志喜欢自己写脚本抓取数据分析日志,然后在zabbix上展示出来.但是开发要看日志的时候, ...

  10. git公钥生成以及与coding等联合

    更好用的 https://segmentfault.com/a/1190000002645623 其中 $ ssh -T git@github.comgitbub $ ssh -T git@git.c ...