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 Collection - 001 集合的遍历
import java.util.ArrayList; import java.util.Iterator; import java.util.List; import com.java.domain ...
- Azure SQL 数据库仓库Data Warehouse (4) 2018 TechSummit 动手实验营
<Windows Azure Platform 系列文章目录> 上传一下之前在2018 TechSummit的动手实验营:Azure数据仓库PaaS项目架构规划与实战入门 包含PPT和Wo ...
- [zz]如何学习Polygon Mesh Processing这本书?
图形学初学者,如何学习Polygon Mesh Processing这本书?修改修改 导师暑假让我看看这本书,目前看了一半觉得这本书比较偏重数学基础,对于具体的 implementation提及的并不 ...
- 03-封装BeanUtil工具类(javabean转map和map转javabean对象)
package com.oa.test; import java.beans.BeanInfo; import java.beans.IntrospectionException; import ja ...
- C#将List<T>转化为DataTable
using System; using System.Collections.Generic; using System.Data; using System.Reflection; using Sy ...
- MSB8013
解决方案: 去掉勾选
- MM-实际应用中的难题
SAP系统实际应用中的十大难题——塞依SAP培训 难题1:采购料维修 如果有物料坏了,需要退回给供应商处维修,此时一般不做退货.因为,第一,供应商不一定会乐意:第二,往来单据也无谓地增多:第三,最重要 ...
- epoll的LT和ET(转)
1 socket IO事件 1.1 读事件 读事件:句柄从不可读变成可读,或者句柄写缓冲区有新的数据进来且超过SO_RCVLOWAT. 常见的产生读事件有如下几种: socket有一个未清除的错误.如 ...
- springboot @Value获取值为空,解决办法
在spring中,常常使用 @Value("${property}") 从application.properties中取值,需要注意两点 使用 @Value 的类不能使用 new ...
- 接口自动化测试链接https://www.cnblogs.com/finer/
https://www.cnblogs.com/finer/ 测试框架的基本原则:业务逻辑与测试脚本分离,测试脚本与测试数据分离: 接口自动化的两种方式:工具(jmeter).代码(使用的是pytho ...