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号点的最小 ...
随机推荐
- fiddler https
fiddler 里面的action 点选remove的那个 手机端清理凭据 在重新添加(在手机浏览器先输入代理的地址 下载证书 之后再安装)
- 【Vue】input textarea自动滚动到输入处
由于我这里要把接口返回的日志不断地新增到textarea里,想实现自动滚动日志的效果. 1.首先定一个textarea类型的input组件 <el-input id="textarea ...
- (Java多线程系列一)快速入门
Java多线程快速入门 1.线程和进程的区别 进程是所有线程的集合,每一个线程是进程的一条执行路径. 2.多线程的应用场景 多线程主要体现在提高程序的效率,比如迅雷多线程下载,多线程分批发送短信等. ...
- koa2,koa-jwt中token验证实战详解
用户身份验证通常有两种方式,一种是基于cookie的认证方式,另一种是基于token的认证方式.当前常见的无疑是基于token的认证方式.以下所提到的koa均为koa2版本. token认证的优点是无 ...
- Ajax+PHP实现的进度条--实例
之前重点学习PHP,所以javascript.Ajax都比较弱一点.现在也开始补课了,今天实现了一个进度条的例子,感觉Ajax实现动态页面真的很厉害,并没有想象中的那么难理解. 进度条作为反应实时传输 ...
- iframe标签的初试
要使用的框架的页面代码: <body> <form id="form1" runat="server"> <div> < ...
- MySQL 数据库 高级查询
1.连接查询select * from Info,Nation #笛卡尔积select * from Info,Nation where Info.Nation=Nation.Code join on ...
- Vue路由器的简单实现
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Uep的confirm和alert弹窗
$.confirm("确认删除", "确定删除所选服务么?", function() { ajaxgrid.delCheckedRecords(); var g ...
- 浅谈Uep分页查询
<hy:ajaxgrid id="unitGrid" showpagerbar="true" name="unitWrap" show ...