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号点的最小 ...
随机推荐
- JS实现表格隔行变色
用到的鼠标事件:(1)鼠标经过 onmouseover:(2)鼠标离开 onmouseout 核心思路:鼠标经过 tr 行的时候,当前行会改变背景颜色,鼠标离开的时候去掉背景颜色. 注意:第一行(th ...
- windows10禁止系统更新
- Qt修改图片的背景色及设置背景色为透明的方法
先上干货. Qt下修改图片背景色的方法: 方法一: QPixmap CKnitWidget::ChangeImageColor(QPixmap sourcePixmap, QColor origCol ...
- Java多线程和并发(六),yield函数和中断线程
目录 1.yield函数 2.中断线程 六.yield函数和中断线程 1.yield函数 2.中断线程 (1)已经被抛弃的方法 (2)目前使用的方法
- 利用pdfbox和poi抽取pdf、doc以及docx格式的内容
使用pdfbox1.5.0抽取pdf格式文档内容,使用poi3.7抽取doc及docx文档内容: /** * Created by yan.shi on 2017/9/25. */ import or ...
- python学习之路(4)
使用list和tuple Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 比如,列出班里所有同学的名字,就可以用一个list表示: >& ...
- LeetCode 18. 四数之和(4Sum)
题目描述 给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等? ...
- MyExcel 2.2.0 版本发布,支持公式导出
MyExcel,是一个集导入.导出.加密Excel等多项功能的java工具包. 相关链接 MyExcel 的详细介绍:点击查看 MyExcel 的下载地址:点击下载
- Cascader 级联选择器
当一个数据集合有清晰的层级结构时,可通过级联选择器逐级查看并选择. 基础用法 有两种触发子菜单的方式 只需为 Cascader 的options属性指定选项数组即可渲染出一个级联选择器. 通过expa ...
- zk 两阶段提交(待完善)
zk 节点是一个 QuorumPeer,选举结束后,leader 和 follower 各自执行自己的逻辑: org.apache.zookeeper.server.quorum.QuorumPeer ...