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 ...
随机推荐
- Java环境配置之JDK安装
一.下载 现在JDK的版本很多.我下载的是jdk1.7 以下链接是jdk1.8的 http://www.oracle.com/technetwork/java/javase/downloads/jdk ...
- 上线啦,PP.io!
经过我们PPIO团队成员们在20天零13小时零14分的辛勤努力下,我们的官网终于上线了! 是的,14年前我们就是东半球第一个P2P技术团队.我们的征程始于2004年春天一个温暖的午后.寝室里笨拙的 ...
- iOS ReactiveCocoa的使用
一.ReactiveCocoa简介 reactiveCocoa简称RAC,它是一个三方框架,很多人把它叫做函数响应式编程框架,因为它具有函数式编程和响应式编程的特性. 由于该框架的编程思想,使得它具有 ...
- 备份与还原mysql 数据库的常用命令。
一.备份数据: Mysqldump常用命令: mysqldump -u用户名 -p密码 --databases 数据库1 数据库2 > xxx.sql 常见选项: -u: 用户名 -p: 密码 ...
- 如何在idea里面新建一个maven项目,然后在这个maven项目里创建多个子模块
如何在idea里面配置maven我这里就不多说了 先新建一个maven项目作为总的管理项目 不用勾选什么,直接下一步 这样子一个普通的maven项目就创建成功了. 因为这个项目是用来管理多个子模块的, ...
- mysql Mac篇
默认为mysql下载和安装完毕,安装为默认安装 下载地址:https://dev.mysql.com/downloads/file/?id=473576 1.启动mysql sudo /usr/loc ...
- 一、CSS介绍
CSS介绍 1.css概述: CSS指层叠样式表 CSS样式表极大地提高了工作效率 selector{ property:value } 注:property(属性)大于1之后,property之间用 ...
- JAVA方法参数传递
package demo.methodparamDemo; public class MethodParamsDemo { public static void main(String[] args) ...
- 基于LNMP的Zabbix4.0.1部署
转:http://www.safecdn.cn/monitor/2018/12/lnmp-zabbix4-0-1-install/306.htmlZabbix4.0.1部署 一 安装源和Zabb ...
- oracle 11g密码过期问题解决方法
ORACLE 11G密码过期问题: 1.使用oracle用户进入sql编辑器中执行修改密码(原始密码,保持不变)的命令 sql>alter user 用户名 identified by &quo ...