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 nn blocks labelled from 11 to nn. 
Bessie lives in the first block while Elsie lives in the nn-th one. They have a map of the farm 
which shows that it takes they titi minutes to travel from a block in EiEito another block 
in EiEi where Ei (1≤i≤m)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.

InputThe first line contains an integer T (1≤T≤6)T (1≤T≤6), the number of test cases. Then TT test cases 
follow.

The first line of input contains nn and mm. 2≤n≤1052≤n≤105. The following mm lines describe the sets Ei (1≤i≤m)Ei (1≤i≤m). Each line will contain two integers ti(1≤ti≤109)ti(1≤ti≤109) and Si (Si>0)Si (Si>0) firstly. Then SiSi integer follows which are the labels of blocks in EiEi. It is guaranteed that ∑mi=1Si≤106∑i=1mSi≤106.OutputFor 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.Sample Input

2
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

Sample Output

Case #1: 3
3 4
Case #2: Evil John

可以将给顶集合的元素连到一个虚拟结点上,求出最短路来再/2,这样避免了大量的重复加边,还避免了小数

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 5e5 ; #define INF 0x3f3f3f3f /*
连接虚拟结点
到该点的距离为L
求出最短路/2 避免小数!
*/
LL T, d, n, m, cnt;
struct edge
{
edge(LL _a,LL _b):to(_a),cost(_b){}
LL to, cost;
};
vector<edge>E[MAXN];
LL dist1[MAXN], dist2[MAXN];
bool vis[MAXN];
void addedge(LL f,LL to,LL dis)
{
E[f].push_back(edge(to, dis));
E[to].push_back(edge(f, dis));
}
void init()
{
for (LL i = ; i < MAXN; i++)
E[i].clear();
}
void spfa(LL beg, LL lowcost[])
{
queue<LL> q;
memset(vis, false, sizeof(vis));
for (int i = ; i <= n + m; i++)
lowcost[i] = INF;
lowcost[beg] = ;
vis[beg] = true;
q.push(beg);
while (!q.empty())
{
LL f = q.front();
q.pop();
vis[f] = false;
for (int i = ; i < E[f].size(); i++)
{
if (lowcost[E[f][i].to] > lowcost[f] + E[f][i].cost)
{
lowcost[E[f][i].to] = lowcost[f] + E[f][i].cost;
if (!vis[E[f][i].to])
{
vis[E[f][i].to] = true;
q.push(E[f][i].to);
}
}
}
}
}
int main()
{
scanf("%lld", &T);
for(LL cas = ;cas <= T; cas++)
{
init();
scanf("%lld%lld", &n, &m);
LL tmp, tt;
for (LL i = ; i <= m; i++)
{
scanf("%lld%lld", &d, &tmp);
while (tmp--)
{
scanf("%lld", &tt);
addedge(tt, n + i, d);
}
}
spfa(, dist1);
spfa(n , dist2);
LL ans = INF;
for (int i = ; i <= n; i++)
ans = min(ans, max(dist1[i], dist2[i]));
if (ans == INF)
printf("Case #%lld: Evil John\n", cas);
else
{
printf("Case #%lld: %lld\n", cas, ans / );
bool f = false;
for (int i = ; i <= n; i++)
{
if (max(dist1[i], dist2[i]) == ans)
{
if (!f)
printf("%d", i), f = true;
else
printf(" %d", i);
}
}
printf("\n");
}
}
}

Meeting 加虚拟边的更多相关文章

  1. HDU 5521 Meeting(虚拟节点+最短路)

    Meeting Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total ...

  2. Qt - 锁屏界面加虚拟小键盘

    一.实现效果 鼠标点击"密码输入栏",弹出虚拟键盘,输入锁屏密码后,点击虚拟键盘外部区域,则会隐藏虚拟键盘,再点击登录,成功进入主界面. 二.虚拟键盘-程序设计 2.1 frmNu ...

  3. Wampserver-添加虚拟主机

    鼠标左键点击,之后点击第一个 localhost(有一个小房子) 添加虚拟地址 具体添加 完成界面 注意:这个时候一定需要重启一个Wampserver64 如果没有重启直接进入4这个步骤,会发现进入的 ...

  4. ASP.NET 小白从零开始建站简易教程 (一)域名、虚拟主机、FTP上传文件

    只考虑性价比,纯新手实验无备案.跟着步骤走半小时即可收获独立的个人网站一枚! 我的实验站 http://www.bearlab.site/ ⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄ 目前总价花费86元(域名加虚 ...

  5. iis express添加虚拟目录

    在调试WEB时,还是使用IIS EXPRESS比较方便, 在IIS中,选择网站,右击,添加虚拟目录或者应用程序,就能添加虚拟目录了.. 在IIS EXPRESS中,添加虚拟目录如下 1.右击IIS E ...

  6. 虚拟机上CentOS-6.9-x86_64系统安装教程

    最近想学学Linux系统如何使用,于是想用VM安装虚拟机学习一下. linux系统比较多,我这里用的是CentOS-6.9-x86_64 一.下载系统 下载地址:https://www.centos. ...

  7. Oracle性能调优之虚拟索引用法简介

    本博客记录一下Oracle虚拟索引的用法,虚拟索引是定义在数据字典中的伪索引,可以说是伪列,没有修改的索引字段的.虚拟索引的目的模拟索引,不会增加存储空间的使用,有了虚拟索引,开发者使用执行计划的时候 ...

  8. 通过LVS+Keepalived搭建高可用的负载均衡集群系统

    1. 安装LVS软件      (1)安装前准备操作系统:统一采用Centos6.5版本,地址规划如下: 服务器名 IP地址 网关 虚拟设备名 虚拟ip Director Server 192.168 ...

  9. Hadoop集群(第1期)_CentOS安装配置

    CentOS 是什么? CentOS是一个基于Red Hat 企业级 Linux 提供的可自由使用的源代码企业级的 Linux 发行版本.每个版本的 CentOS 都会获得七年的支持(通过安全更新方式 ...

随机推荐

  1. Redux中的异步操作

    异步操作的另一种方案就是让Action Creator返回一个Promise对象. 我们这边使用  redux-promise  中间件 import { createStore, applyMidd ...

  2. 短视频SDK超级简单易用

    超级简单易用的短视频SDK来自RDSDK.COM.锐动天地为开发者提供短视频编辑.视频直播.特效.录屏.编解码.视频转换,等多种解决方案,涵盖PC.iOS.Android多平台.以市场为导向,不断打磨 ...

  3. CentOS6.8 RPM包安装快速zabbix22

    CentOS6.8 RPM包安装快速zabbix22 yum install -y epel-release # yum install -y httpd php php-devel mysql-se ...

  4. Shiro的subject实质上是当前执行用户的特定视图。

    Shiro的subject实质上是当前执行用户的特定视图. 通过org.apache.shiro.SecurityUtils可以查询当前执行用户: Subject currentUser = Secu ...

  5. nodejs的学习

    nodejs 就是使用js来编写服务端的程序.它的特性是(单线程   速度快   耗内存多  异步   事件驱动) ( 一些技术的解决方案:默认情况下是 1.不支持多核,可以使用cluster 进行解 ...

  6. Linux 控制终端转义和控制序列

    DESCRIPTION 描述 Linux控制台实现了VT102和ECMA-48/ISO 6429/ANSI X3.64终端控制的子集, 这个子集很庞大,当然还有Linux自己私有的控制序列,以改变颜色 ...

  7. pycharm 编写前端代码一些小技巧

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...

  8. mac 目录颜色设置

    1 export CLICOLOR=1  2 export LSCOLORS=gxfxaxdxcxegedabagacad

  9. 看完这篇 你就能完全操作git 远程分支的增、删、改、查了

    最近项目中又用到了git所以在此总结一番,这篇主要针对的是怎么创建远程分支,如何删除远程分支. 首先,如何创建远程分支.将一系列前期准备工作准备完成后(创建\添加ssh): 在终端键入 git bra ...

  10. CentOS虚拟机挂载Windows共享目录

    Windows文件共享使用了SMB协议(又称CIFS协议),该协议主要提供了文件共享和打印共享功能,分别使用TCP 139和445端口.UNIX.Linux系统提供了该协议的开源实现samba.为了方 ...