博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu5521 Meeting
阅读量:7082 次
发布时间:2019-06-28

本文共 3664 字,大约阅读时间需要 12 分钟。

题目

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 (1im) 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 (1T6), the number of test cases. Then T test casesfollow.
The first line of input contains n and m. 2n105. The following m lines describe the sets Ei (1im). Each line will contain two integers ti(1ti109) and Si (Si>0) firstly. Then Si integer follows which are the labels of blocks in Ei. It is guaranteed that mi=1Si106.
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;vector
v[200100];priority_queue
>q;int vis[210000],d1[210000],d2[210000],val[210000];int ans[210000];int main(){ int n,m,i,j,k,t,p,s,x; scanf("%d",&t); for(p=1;p<=t;p++){ scanf("%d%d",&n,&m); for(i=1;i<=n+m;i++)v[i].clear(); memset(vis,0,sizeof(vis)); memset(d1,0x3f,sizeof(d1)); memset(d2,0x3f,sizeof(d2)); memset(val,0,sizeof(val)); for(i=1;i<=m;i++){ scanf("%d%d",&val[i+n],&s); for(j=1;j<=s;j++){ scanf("%d",&x); v[x].push_back(i+n); v[i+n].push_back(x); } } d1[1]=0; q.push(make_pair(0,1)); while(!q.empty()){ x=q.top().second; q.pop(); if(vis[x])continue; vis[x]=1; for(i=0;i
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 (1im) 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 (1T6), the number of test cases. Then T test cases
follow.
The first line of input contains n and m. 2n105. The following m lines describe the sets Ei (1im). Each line will contain two integers ti(1ti109) and Si (Si>0) firstly. Then Si integer follows which are the labels of blocks in Ei. It is guaranteed that mi=1Si106.
 

 

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.

转载于:https://www.cnblogs.com/yzxverygood/p/9200776.html

你可能感兴趣的文章
新浪、万网前系统架构师高俊峰:统一监控报警平台架构设计思路
查看>>
2011-9-25俱乐部活动
查看>>
JMeter正则表达式提取器
查看>>
Nginx
查看>>
How To Enable‘root’Account Login Solaris 11 Directly
查看>>
MongoDB学习初步
查看>>
sccm 2007 r2 step by step 之十二 操作系统分发part1
查看>>
Tokyo Tyrant基本规范(1)--介绍和安装
查看>>
ORA-30036故障处理思路
查看>>
Advanced Threat Analytics 2016
查看>>
SFB 项目经验-31-批量为n台服务器导入PFX证书
查看>>
PostgreSQL存储过程<转>
查看>>
Angular企业级开发(8)-控制器的作用域
查看>>
BZOJ 4538: [Hnoi2016]网络 [整体二分]
查看>>
从XML文件乱码问题,探寻其背后的原理
查看>>
BSD Socket~TCP~Example Code
查看>>
Spring配置文件总结
查看>>
CodeForces 388A Fox and Box Accumulation (模拟)
查看>>
C/C++拾遗(一):关于数组的指针和数组元素首地址的一道经典题
查看>>
《AndroidStudio每日一贴》5. 怎样高速查看某个方法/注解的定义?
查看>>