POJ-1511 Invitation Cards (双向单源最短路)
Description
The transport system is very special: all lines are
unidirectional and connect exactly two stops. Buses leave the
originating stop with passangers each half an hour. After reaching the
destination stop they return empty to the originating stop, where they
wait until the next full half an hour, e.g. X:00 or X:30, where 'X'
denotes the hour. The fee for transport between two stops is given by
special tables and is payable on the spot. The lines are planned in such
a way, that each round trip (i.e. a journey starting and finishing at
the same stop) passes through a Central Checkpoint Stop (CCS) where each
passenger has to pass a thorough check including body scan.
All the ACM student members leave the CCS each morning.
Each volunteer is to move to one predetermined stop to invite
passengers. There are as many volunteers as stops. At the end of the
day, all students travel back to CCS. You are to write a computer
program that helps ACM to minimize the amount of money to pay every day
for the transport of their employees.
Input
only positive integer N. Then follow the cases. Each case begins with a
line containing exactly two integers P and Q, 1 <= P,Q <= 1000000.
P is the number of stops including CCS and Q the number of bus lines.
Then there are Q lines, each describing one bus line. Each of the lines
contains exactly three numbers - the originating stop, the destination
stop and the price. The CCS is designated by number 1. Prices are
positive integers the sum of which is smaller than 1000000000. You can
also assume it is always possible to get from any stop to any other
stop.
Output
be paid each day by ACM for the travel costs of its volunteers.
Sample Input
Sample Output
# include<iostream>
# include<cstdio>
# include<cstring>
# include<queue>
# include<algorithm>
using namespace std;
const int N=;
const long long INF=<<;
struct edge
{
int to,w,nxt;
};
edge e[N+];
int n,cnt,head[N+],a1[N+],a2[N+],c[N+];
long long dis[N+];
void add(int u,int v,int w)
{
e[cnt].to=v;
e[cnt].w=w;
e[cnt].nxt=head[u];
head[u]=cnt++;
}
long long spfa()
{
fill(dis,dis+n+,INF);
queue<int>q;
q.push();
dis[]=;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u];i!=-;i=e[i].nxt){
if(dis[e[i].to]>dis[u]+e[i].w){
dis[e[i].to]=dis[u]+e[i].w;
q.push(e[i].to);
}
}
}
long long res=;
for(int i=;i<=n;++i)
res+=dis[i];
return res;
}
int main()
{
int T,m;
scanf("%d",&T);
while(T--)
{
cnt=;
scanf("%d%d",&n,&m);
fill(head,head+n+,-);
for(int i=;i<m;++i){
scanf("%d%d%d",&a1[i],&a2[i],&c[i]);
add(a1[i],a2[i],c[i]);
}
long long ans=spfa();
//cout<<ans<<endl;
cnt=;
fill(head,head+n+,-);
for(int i=;i<m;++i)
add(a2[i],a1[i],c[i]);
ans+=spfa();
printf("%lld\n",ans);
}
return ;
}
POJ-1511 Invitation Cards (双向单源最短路)的更多相关文章
- POJ 1511 Invitation Cards ( 双向单源最短路 || 最小来回花费 )
题意 : 给出 P 个顶点以及 Q 条有向边,求第一个点到其他各点距离之和+其他各点到第一个点的距离之和的最小值 分析 : 不难看出 min( 第一个点到其他各点距离之和+其他各点到第一个点的距离之和 ...
- POJ 1511 Invitation Cards(单源最短路,优先队列优化的Dijkstra)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 16178 Accepted: 526 ...
- POJ-1511 Invitation Cards (单源最短路+逆向)
<题目链接> 题目大意: 有向图,求从起点1到每个点的最短路然后再回到起点1的最短路之和. 解题分析: 在求每个点到1点的最短路径时,如果仅仅只是遍历每个点,对它们每一个都进行一次最短路算 ...
- POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...
- poj 1511 Invitation Cards (最短路)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 33435 Accepted: 111 ...
- Invitation Cards POJ - 1511 (双向单源最短路)
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
- Poj 1511 Invitation Cards(spfa)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...
- SPFA算法(2) POJ 1511 Invitation Cards
原题: Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 31230 Accepted: ...
随机推荐
- Vlock用于有多个用户访问控制台的共享 Linux 系统
当你在共享的系统上工作时,你可能不希望其他用户偷窥你的控制台中看你在做什么.如果是这样,我知道有个简单的技巧来锁定自己的会话,同时仍然允许其他用户在其他虚拟控制台上使用该系统. 要感谢Vlock(Vi ...
- Elasticsearch 疑难解惑
Elasticsearch是如何实现Master选举的? Elasticsearch的选主是ZenDiscovery模块负责的,主要包含Ping(节点之间通过这个RPC来发现彼此)和Unicast(单 ...
- JavaScript 读取修改元素 及 伸拉门案例
JavaScript 读取修改元素 及 伸拉门案例 版权声明:未经授权,严禁转载! 读取 / 修改元素 - 读取修改元素内容 - 读取修改元素属性 - 读取修改元素样式 元素的内容 读取或修改元素节点 ...
- 20145333茹翔《网络对抗》Exp9 Web安全基础实践
20145333茹翔<网络对抗>Exp9 Web安全基础实践 基础问题回答 1.SQL注入原理,如何防御 SQL注入 就是通过把SQL命令插入到"Web表单递交"或&q ...
- IPMB接口协议总结
IPMB接口协议总结 IPMB,智能平台管理总线, 是ATCA(Advanced Telecom Computing Architecture)先进的电信计算平台的各FRU背板通讯的两组冗余I2C总线 ...
- cmd命令分类
1.系统功能类 AT:计划在计算机上运行的命令和程序.ATTRIB:显示或更改文件属性.BREAK:设置或清除扩展式 CTRL+C 检查.CACLS:显示或修改文件的访问控制列表(ACLs).CALL ...
- Python3基础 str title 单词首字母大写,其余均为小写
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 常用模块之hashlib,subprocess,logging,re,collections
hashlib 什么是hashlib 什么叫hash:hash是一种算法(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,M ...
- 【基础知识】ActiveMQ基本原理
“来,根据你的了解说下 ActiveMQ 是什么.” “这个简单,ActiveMQ 是一个 MOM,具体来说是一个实现了 JMS 规范的系统间远程通信的消息代理.它……” “等等,先解释下什么是 MO ...
- 【第二十九章】 springboot + zipkin + mysql
zipkin的数据存储可以存在4个地方: 内存(仅用于测试,数据不会持久化,zipkin-server关掉,数据就没有了) 这也是之前使用的 mysql 可能是最熟悉的方式 es Cassandra ...