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号点的最小 ...
随机推荐
- 2019春Python程序设计练习4(4.9-4.15)
1-1 如下代码可以实现当输入6的时候输出x>5,输入4的时候输出 3<x<=5,输入1的时候输出x<=3 x = int(input()) if x>5: print( ...
- linux 免密码 使用sudo 直接使用root权限执行命令
1.切换到root用户下,怎么切换就不用说了吧,不会的自己百度去. 2.添加sudo文件的写权限,命令是: chmod u+w /etc/sudoers 3.编辑sudoers文件 vi /etc/s ...
- Pod初始化容器之Init Container
Init 容器的介绍 Pod能够具有多个容器,应用运行在容器里面,但是它也可能有一个或多个先于应用容器启动的 Init容器Init 容器与普通的容器非常像,除了如下两点: c Init 容器总是运行 ...
- layui button按钮点击导致页面重新刷新的解决方案
网友的解决方法:(我只想说,放屁!!!而且大家都在复制粘贴,浪费时间) 方法一:将button标签更换为input <input class="layui-btn test" ...
- CF1213E Two Small Strings
题目链接 问题分析 由于三个字母是等价的,所以大致可以分为如下几种情况: aa, ab ab, ac ab, ba ab, bc 不难发现,第\(3\)中情况可能造成无解(\(n>1\)时),而 ...
- Windows下如何安装Redis
Redis可以从下面的github上面下载,当前的下载版本为3.2.100版本 https://github.com/MicrosoftArchive/redis/releases 这边都是64位的链 ...
- 出现org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER, 且出现无法找到Maven的依赖的问题
解决方案:Build Path -> Java Build Path ->Libraries ->Add Library ->Maven Managed Dependences ...
- LeetCode19----删除链表的倒数第N个节点
给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点. 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 ...
- LeetCode 98. 验证二叉搜索树(Validate Binary Search Tree)
题目描述 给定一个二叉树,判断其是否是一个有效的二叉搜索树. 假设一个二叉搜索树具有如下特征: 节点的左子树只包含小于当前节点的数. 节点的右子树只包含大于当前节点的数. 所有左子树和右子树自身必须也 ...
- oracle11g RMAN catalog的基本使用
编辑 /etc/hosts文件 tnsnames.ora文件 创建SQL> create tablespace ts_rman_catalog datafile '/u01/app/oracle ...