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. webapp开发学习---Cordova环境搭建

    Cordova 使用HTML, CSS & JS进行移动App开发;多平台共用一套代码;免费开源 步骤:(来自Cordova官网) 1.安装Cordova(在node.js环境下进行安装) 命 ...

  2. CentOS 7 下配置 firewalld(firewall-cmd)实现 NAT 转发 软路由

    如果配合 DHCP 服务或实现更多功能. ☼ NAT 转发软路由 开启 NAT 转发之后,只要本机可以上网,不论是单网卡还是多网卡,局域网内的其他机器可以将默认网关设置为已开启 NAT 转发的服务器 ...

  3. Bmob使用心得

    1.在 Project 的 build.gradle 文件中添加 Bmob的maven仓库地址,示例如下:(注意文字说明部分): allprojects { repositories { jcente ...

  4. Android习惯——给全部Activity添加集合管理

    title: 2017-3-23 Android习惯--给全部Activity添加集合管理 public void ActivityCollector{ public static List<A ...

  5. vue2.0生命周期函数

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 习水医院12C RAC 数据库安装文档

        环境介绍 OS: Oracle Enterprise Linux 6.4 (For RAC Nodes) DB: GI and Database 12.1.0.2 所需介质 p17694377 ...

  7. js 复制文字、 复制链接到粘贴板

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 经典问题——输出n对括号的所有组合

    问题 n对括号有多少种合法的组合,比如两对括号可以有两种:()()和(()) 思路 问题等价为:在一个字符串中包含两种字符:'('和')',他们出现的次数都为n,并且任何时候'('出现的次数总是大于或 ...

  9. spark版本不支持(降版本打包)

    在做项目的时候代码已经更新为hadoop 2.7  spark 2.1 scala 2.11.8版本,但是服务器版本使用的是hadoop2.6 spark1.6 以及scala2.10.6版本,,主程 ...

  10. 【C语言】控制台窗口图形界面编程(二)窗口信息和填充缓冲区

    目录 00. 目录 01. COORD结构体 02. SMALL_RECT结构 03. CONSOLE_SCREEN_BUFFER_INFO结构体 04. GetConsoleScreenBuffer ...