2015沈阳区域赛Meeting(最短路 + 建图)
Meeting
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 6865 Accepted Submission(s): 2085
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.
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.
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.
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
3 4
Case #2: Evil John
In the first case, it will take Bessie 1 minute travelling to the 3rd block, and it will take Elsie 3 minutes travelling to the 3rd block. It will take Bessie 3 minutes travelling to the 4th block, and it will take Elsie 3 minutes travelling to the 4th block. In the second case, it is impossible for them to meet.
/*************************************************************************
> File Name: meeting.cpp
> Author: CruelKing
> Mail: 2016586625@qq.com
> Created Time: 2019年09月21日 星期六 11时26分48秒
本题思路:用Dijkstra结果wa了,很无奈,换了spfa就过了,哦,不是就过了,是
各种TLE,WA,PE都不提示,给别人提示的是WA,时段不同也能T.搞心态的题......
就是个傻逼题:稍加分析就知道一个块内全部建边是不可行的,对每个块建立一个超级
源点,块内的点向超级源点连一条边,跑一波最短路,后续细节处理很简单.傻逼题.
************************************************************************/ #include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std; const int maxn = + , maxm = + ; typedef long long ll; ll inf = LLONG_MAX; struct Edge {
int to, cost, next;
} edge[maxm << ]; int head[maxn], tot; int n, m; ll diss[maxn], dist[maxn]; ll dis[maxn]; bool vis[maxn]; void init() {
memset(head, -,sizeof head);
tot = ;
} void addedge(int u, int v, int w) {
edge[tot].to = v; edge[tot].cost = w; edge[tot].next = head[u]; head[u] = tot ++;
edge[tot].to = u; edge[tot].cost = w; edge[tot].next = head[v]; head[v] = tot ++;
} void dijkstra(int s, ll (&_dis)[maxn]) {
memset(vis, false, sizeof vis);
for(int i = ; i <= m + n; i ++) _dis[i] = inf;
_dis[s] = ;
vis[s] = true;
queue <ll> que;
que.push(s);
while(!que.empty()) {
int u = que.front(); que.pop(); vis[u] = false;
for(int i = head[u]; ~i; i = edge[i].next) {
int v = edge[i].to;
if(_dis[v] > _dis[u] + edge[i].cost) {
_dis[v] = _dis[u] + edge[i].cost;
if(!vis[v]) {
vis[v] = true;
que.push(v);
}
}
}
}
} int ans[maxn], cnt; int main() {
int t, v, w, num, _case = ;
scanf("%d", &t);
while(t --) {
cnt = ;
init();
// memset(dis, inf ,sizeof dis);
scanf("%d %d", &n, &m);
for(int i = ; i <= n + m; i ++) dis[i] = inf;
for(int u = ; u <= m; u ++) {
scanf("%d %d", &w, &num);
while(num --) {
scanf("%d", &v);
addedge(u, m + v, w);
}
}
dijkstra( + m, diss);
dijkstra(n + m, dist);
ll Min = inf;
for(int i = + m; i <= n + m; i ++) {
if(diss[i] < inf && dist[i] < inf) {
dis[i] = max(diss[i], dist[i]);
if(dis[i] < Min) Min = dis[i];
}
}
printf("Case #%d: ", ++ _case);
if(Min != inf) {
printf("%lld\n", Min / );
for(int i = + m; i <= n + m; i ++) {
if(dis[i] == Min) {
ans[cnt ++] = i - m;
}
}
for(int i = ; i < cnt; i ++) {
if(i) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
} else printf("Evil John\n");
}
return ;
}
2015沈阳区域赛Meeting(最短路 + 建图)的更多相关文章
- 第八届河南省赛C.最少换乘(最短路建图)
C.最少换乘 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 94 Solved: 25 [Submit][Status][Web Board] De ...
- 2017 ICPC/ACM 沈阳区域赛HDU6223
Infinite Fraction Path Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java ...
- HDU5521-最短路-建图
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU 5521 [图论][最短路][建图灵感]
/* 思前想后 还是决定坚持写博客吧... 题意: n个点,m个集合.每个集合里边的点是联通的且任意两点之间有一条dis[i]的边(每个集合一个dis[i]) 求同时从第1个点和第n个点出发的两个人相 ...
- hdu4725 The Shortest Path in Nya Graph【最短路+建图】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4297574.html ---by 墨染之樱花 题目链接:http://acm.hdu ...
- Codeforces 938D. Buy a Ticket (最短路+建图)
<题目链接> 题目大意: 有n座城市,每一个城市都有一个听演唱会的价格,这n座城市由m条无向边连接,每天变都有其对应的边权.现在要求出每个城市的人,看一场演唱会的最小价值(总共花费的价值= ...
- hdu 5294 Tricks Device 最短路建图+最小割
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Tricks Device Time Limit: 2000/1000 MS (Java/Other ...
- hdu 4725 The Shortest Path in Nya Graph (最短路+建图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 『The Captain 最短路建图优化』
The Captain(BZOJ 4152) Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小 ...
随机推荐
- centos7安装dockers
安装Docker我是虚拟机装的Centos7,linux 3.10 内核,docker官方说至少3.8以上,建议3.10以上(ubuntu下要linux内核3.8以上, RHEL/Centos 的内核 ...
- vs 2019 调试web项目 浏览器
- 任务Task、先后任务
Task类似后台线程. using System; using System.Threading; using System.Threading.Tasks;//引用命名空间 namespace Co ...
- Java多线程和并发(十),JMM(Java内存模型)
目录 1.什么是JMM 2.JMM的主内存和工作内存 3.JMM如何解决可见性问题-指令重排序 4.Volatile 十.JMM(Java内存模型)(暂时没有理解) 1.什么是JMM 2.JMM的主内 ...
- Unity3D_(API)Quaternion四元数中的Quaternion.LookRotation()
四元数百度百科: 传送门 四元数官方文档: 传送门 欧拉旋转.四元数.矩阵旋转之间的差异: 传送门 四元数转换为欧拉角eulerAngles 官方文档: 传送门 欧拉角转换为四元数Euler 官方文档 ...
- [EOJ Monthly2019.11][T4]安全带
以下是题干 D. 安全带 单点时限: 1.0 sec 内存限制: 256 MB (前面题干是一堆废话,我把它删了) 简单来说:初始给出一个 n 个点顺次连接而成的环,点有点权,边权是两个端点的点权乘积 ...
- 分布式-信息方式-ActiveMQ的Message dispatch高级特性之(指针) Message cursors
Message dispatch高级特性之 Message cursors概述 ActiveMQ发送持久消息的典型处现方式是:当消息的消费者准备就绪时,消息发送系统把存储的 消息 ...
- Vue CLi3入门
摘自:https://www.jianshu.com/p/cf9b56efd3b8 Vue CLi3入门 12018.11.15 14:16:17字数 1222阅读 8895 地址 Vue CLi3 ...
- electron--Tray添加图标和上下文菜单到系统通知区(系统托盘)
const { app, Menu, Tray } = require('electron'); //系统托盘图标目录 appTray = new Tray(path.join(__dirname, ...
- mingw下的msys显示与输入乱码
一直很喜欢gcc+vim这个貌似已经不用在强调了,好了,我只是想说明下我的问题是首先从gcc编译出错提示开始的 正如上面所说,安装完MinGW后使用gcc一编译,这程序没有错误还好,这一有错误发现输入 ...