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. 策略模式--Java篇

    策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...

  2. 把json数据转化成对象

    把json数据转化到一个对象中,再用对象直接调用 package com.lxj.register; import java.io.BufferedReader; import java.io.IOE ...

  3. windows echo命令

    ECHO命令是大家都熟悉的DOS批处理命令的一条子命令,但它的一些功能和用法也许你并不是全都知道,不信你瞧:  1. 作为控制批处理命令在执行时是否显示命令行自身的开关 格式:ECHO [ON|OFF ...

  4. template or render function not defined.

    template or render function not defined. H_婷 关注 2018.08.16 17:22 字数 106 阅读 3859评论 0喜欢 2 下午写 Vue $par ...

  5. 解决docker pull镜像速度慢的问题

    直接下载Docker镜像时,由于种种原因,经常下载失败,即使连接成功也是很慢,怎么办呢 目前我知道可以提升速度的办法:DaoCloud 提供Docker Hub Mirror服务 用户可以进入Dock ...

  6. cookie存储位置

    平时各位在做项目时多半时候都会用到客户端的cookie,可大家知道cookie是存储在哪里吗? 首先cookie失效分为2种: 1:设置过期时间失效(只要设置了过期时间cookie就会存储在硬盘里面) ...

  7. 【VScode】使用VScode 来写markdown时序图

    准备工作 在VScode中下载插件Markdown Preview Enhanced插件 创建一个.md文件 在VScode中打开文件,界面内点击右键可以看到Open preview to the s ...

  8. 离线缓存 application cache

    1. 什么是离线缓存: 离线缓存可以将站点的一些文件缓存到本地,它是浏览器自己的一种机制,将需要的文件缓存下来,以便后期即使没有连接网络,被缓存的页面也可以展示. 例子:比如我们在手机或电脑上访问一个 ...

  9. python清除字符串中无用字符

    将列表val_list中包含的非法字符去掉,illegal_char是非法字符列表 def clear(): illegal_char = [' ','#','%','_','@'] tmp_list ...

  10. 五、面向切面的spring(1)

    spring的依赖注入看完了,接下来是spring中与DI一并重要的AOP了,开始吧,GO. 在软件开发中,散布于应用中多处的功能被称为横切发关注点,通常来讲,这些横切关注点从概念上市与应用的业务逻辑 ...