HDU 5521.Meeting 最短路模板题
Meeting
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 3361 Accepted Submission(s): 1073
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.
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<vector>
using namespace std;
#define eps 0.0000001
typedef long long ll;
typedef pair<int,int> P;
const int maxn=2e5+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e18+;
struct edge
{
int from,to;
ll w;
};
vector<edge>G[maxn];
priority_queue<P,vector<P>,greater<P> >q;
ll dist[][maxn];
void addedge(int u,int v,ll w)
{
G[u].push_back((edge)
{
u,v,w
});
G[v].push_back((edge)
{
v,u,w
});
}
void dij(int t,int s)
{
dist[t][s]=0LL;
q.push(P(dist[t][s],s));
while(!q.empty())
{
P p=q.top();
q.pop();
int u=p.second;
for(int i=; i<G[u].size(); i++)
{
edge e=G[u][i];
if(dist[t][e.to]>dist[t][u]+e.w)
{
dist[t][e.to]=dist[t][u]+e.w;
q.push(P(dist[t][e.to],e.to));
}
}
}
}
void init(int n)
{
for(int i=; i<=*n+; i++) G[i].clear();
}
int main()
{
int T;
scanf("%d",&T);
for(int Case=; Case<=T; Case++)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=; i<=m; i++)
{
int val;
scanf("%lld",&val);
int t;
scanf("%d",&t);
while(t--)
{
int s;
scanf("%d",&s);
addedge(s,n+i,val);
}
}
for(int i=; i<=*n+; i++) dist[][i]=dist[][i]=INF;
dij(,);
dij(,n);
ll ans=INF;
for(int i=; i<=n; i++)
{
//printf("%lld %lld\n",dist[0][i],dist[1][i]);
ans=min(ans,max(dist[][i],dist[][i]));
}
printf("Case #%d: ",Case);
if(ans>=INF) puts("Evil John");
else
{
printf("%lld\n",ans/);
int cou=;
for(int i=; i<=n; i++)
{
if(!cou&&max(dist[][i],dist[][i])==ans) printf("%d",i),cou++;
else if(cou&&max(dist[][i],dist[][i])==ans) printf(" %d",i),cou++;
}
printf("\n");
}
init(n);
}
return ;
}
最短路模板题
HDU 5521.Meeting 最短路模板题的更多相关文章
- poj1511/zoj2008 Invitation Cards(最短路模板题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Invitation Cards Time Limit: 5 Seconds ...
- [poj2449]Remmarguts' Date(K短路模板题,A*算法)
解题关键:k短路模板题,A*算法解决. #include<cstdio> #include<cstring> #include<algorithm> #includ ...
- 牛客小白月赛6 I 公交线路 最短路 模板题
链接:https://www.nowcoder.com/acm/contest/136/I来源:牛客网 题目描述 P市有n个公交站,之间连接着m条道路.P市计划新开设一条公交线路,该线路从城市的东站( ...
- HDU 5521 Meeting(虚拟节点+最短路)
Meeting Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total ...
- HDU 2544 最短路(模板题)
求1到N的最短路径,模板题,以1为源点,用dijkstra算法(可以用优先级队列优化) #include <iostream> #include <algorithm> #in ...
- HDU 2222(AC自动机模板题)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串.问匹配串中含有多少个模式串.注意模式串有重复,所以要累计重复结果. 解题 ...
- HDU 1711 - Number Sequence - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...
- [USACO07FEB]银牛派对Silver Cow Party---最短路模板题
银牛排队 对于我这种蒟蒻来说,还是不要跑一次单元最短路.跑两次好写呀(- ̄▽ ̄)- 而题目中是有向图.如果如果按照题意进行最短路的话.就会出现一个单终点最短路和一个单起点最短路 对于单起点自然就是套模 ...
- POJ 2387 Til the Cows Come Home --最短路模板题
Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include ...
随机推荐
- Python3 字典 setdefault() 方法
Python 字典 setdefault() 函数和get() 方法类似, 如果键不存在于字典中,将会添加键并将值设为默认值. dict.setdefault(key, default=None) k ...
- 一次Windows 安装问题
在 thinpad x250上安装 windows 10时,提示"安装程序无法创建新的系统分区,也无法定位现有系统分区". x250 的主板上自带一个16G的闪存且标识为 主分区, ...
- 如何修改MSSQL的用户名
Alter LOGIN sa DISABLE Alter LOGIN sa WITH NAME = [systemAccount] "systemAccount" 为SA的新名称, ...
- Response的Content-Type一览
文件扩展名 Content-Type(Mime-Type) 文件扩展名 Content-Type(Mime-Type) .* application/octet-stream .tif image/t ...
- Python的xml模块
先来一段xml代码 <?xml version="1.0"?> <data> <country name="Liechtenstein&qu ...
- redis5.0.4 集群搭建
准备工作用两台虚拟机模拟6个节点,一台机器3个节点,创建出3 master.3 salve 环境. redis 采用 redis-5.0.4 版本. 两台虚拟机都是 CentOS ,一台 CentOS ...
- mass create DN
RUN VL10 in the background. http://paperstreetenterprises.com/running-vl10-background/ VL10*开头的TCODE ...
- .net 调用 Matlab生成dll出现的问题(The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception.)
https://cn.mathworks.com/matlabcentral/answers/278399-i-get-an-error-saying-the-type-initializer-for ...
- Java虚拟机------JVM内存区域
JVM内存区域运行时数据区域分为两种: JVM内存区域 运行时数据区域分为两种: 线程隔离的数据区: 程序计数器 Java虚拟机栈 本地方法栈 所有线程程共享的数据区: Java堆 方法区 JVM 内 ...
- linux tail 命令详解
linux ---tail命令 linux中tail命令---用于查看文件内容 最基本的是cat.more和less. 1. 如果你只想看文件的前5行,可以使用head命令,如: head -5 /e ...