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 ...
随机推荐
- JS 60秒后重发送验证码
//settime($("#getPhoneCode"),60); function settime($obj, time) { if (time == 0) { $obj.att ...
- sql job定时备份数据库
---------------------------------------- 对TestDB1进行备份 ---------------------------------------- decla ...
- Delphi XE5 Android 调用手机震动
uses Androidapi.JNI.Os, Androidapi.JNIBridge; function GetVibratorArray(const AIntArr: array of Int6 ...
- c++11 function_typetraits备忘
function traits. 获取函数或成员函数的返回类型,参数类型,参数长度,类类型. 函数参数列表推断基于typelist:http://www.cnblogs.com/flytrace/p/ ...
- WebApi 序列化 循环引用问题
public static void Register(HttpConfiguration config) { // Web API 配置和服务 config.Formatters.Remove(co ...
- LeetCode——727.Minimum Window Subsequence
一.题目链接:https://leetcode.com/problems/minimum-window-substring/ 二.题目大意: 给定两个字符串S和T,要求从S中找出包含T中所有字母的最短 ...
- java File处理
/**************************************************************************************工具类********** ...
- arcgis10.2 打开CAD文件注记乱码
1.使用ARCGIS10.2打开CAD文件,图面显示的注记内容为乱码,属性表中的注记内容正常2.同样的CAD文件在ARCGIS9.3中打开正常出现此情况影响历史数据使用,请求ESRI技术支持注:系统添 ...
- sed -i命令详解
[root@www ~]# sed [-nefr] [动作] 选项与参数: -n :使用安静(silent)模式.在一般 sed 的用法中,所有来自 STDIN 的数据一般都会被列出到终端上.但如果加 ...
- 基于Dubbo框架构建分布式服务(集群容错&负载均衡)
Dubbo是Alibaba开源的分布式服务框架,我们可以非常容易地通过Dubbo来构建分布式服务,并根据自己实际业务应用场景来选择合适的集群容错模式,这个对于很多应用都是迫切希望的,只需要通过简单的配 ...