poj 1511 Invitation Cards (最短路)
| Time Limit: 8000MS | Memory Limit: 262144K | |
| Total Submissions: 33435 | Accepted: 11104 |
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
Output
Sample Input
2
2 2
1 2 13
2 1 33
4 6
1 2 10
2 1 60
1 3 20
3 4 10
2 4 5
4 1 50
Sample Output
46
210
题目大意:
给你一个有向图。求1到所有点和所有点到1的最短路之和。
小小变形的最短路。
所有点到1的最短路。将边都反转过来跑一遍1的单源最短路即可。证明可以自己想一下,很简单。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue> using namespace std; const int maxn=;
const long long inf=; int input[maxn+][]; int to[maxn+];
int w[maxn+];
int nex[maxn+];
int head[maxn+]; //建图
void build(int m)
{
memset(head,-,sizeof(head));
int u0,v0,w0;
for(int i=;i<m;i++)
{
u0=input[i][];
v0=input[i][];
w0=input[i][];
to[i]=v0;w[i]=w0;
nex[i]=head[u0];head[u0]=i;
}
} int vis[maxn+];
int dis[maxn+]; void spfa(int n)
{
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
dis[i]=inf;
queue<int> q;
q.push();
vis[]=;dis[]=;
while(!q.empty())
{
int u0=q.front();q.pop();
for(int i=head[u0];i!=-;i=nex[i])
{
int v0=to[i],w0=w[i];
if(dis[u0]+w0<dis[v0])
{
dis[v0]=dis[u0]+w0;
if(!vis[v0])
{
q.push(v0);
vis[v0]=;
}
}
}
}
} int main()
{
int nn;
scanf("%d",&nn);
while(nn--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<m;i++)
scanf("%d%d%d",input[i],input[i]+,input[i]+); long long ans=; build(m);
spfa(n);
for(int i=;i<=n;i++)
ans+=1LL*dis[i]; for(int i=;i<m;i++)
swap(input[i][],input[i][]);
build(m);
spfa(n);
for(int i=;i<=n;i++)
ans+=1LL*dis[i]; printf("%lld\n",ans);
}
return ;
}
poj 1511 Invitation Cards (最短路)的更多相关文章
- 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(单源最短路,优先队列优化的Dijkstra)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 16178 Accepted: 526 ...
- poj 1511 Invitation Cards(最短路中等题)
In the age of television, not many people attend theater performances. Antique Comedians of Malidine ...
- POJ 1511 Invitation Cards (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
- DIjkstra(反向边) POJ 3268 Silver Cow Party || POJ 1511 Invitation Cards
题目传送门 1 2 题意:有向图,所有点先走到x点,在从x点返回,问其中最大的某点最短路程 分析:对图正反都跑一次最短路,开两个数组记录x到其余点的距离,这样就能求出来的最短路以及回去的最短路. PO ...
- POJ 1511 Invitation Cards (spfa的邻接表)
Invitation Cards Time Limit : 16000/8000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) ...
- Poj 1511 Invitation Cards(spfa)
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 24460 Accepted: 8091 De ...
- (简单) POJ 1511 Invitation Cards,SPFA。
Description In the age of television, not many people attend theater performances. Antique Comedians ...
随机推荐
- 20191107-3 beta week 2/2 Scrum立会报告+燃尽图 02
此作业要求参见[https://edu.cnblogs.com/campus/nenu/2019fall/homework/9955] 一.小组情况 队名:扛把子 组长:孙晓宇 组员:宋晓丽 梁梦瑶 ...
- Python练习100题
Python练习100题 题目:有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? #Filename:001.py cnt = 0#count the sum of res ...
- 2019-10-8:渗透测试,基础学习,php基础,会话,文件包含,笔记
php面向对象基础->调用符号构造函数construct,主要用来创建对象时初始化对象,为成员变量赋初始值,总与new运算符一起使用在创建对象的语句中 析构函数destructor,与构造函数相 ...
- 2 JAVA语言的基本规则
1. 类名 类名需使用字母开头,使用驼峰命名法,如HelloWorld,对应的文件为 HelloWorld.java,与类名保持一致.编译好的字节码文件为 HelloWord.class. 2. 区分 ...
- 前端WEB编辑器最爱——webstrom
欲先善其事,必先利其器,如题.看到网上一篇介绍webstrom的文章,觉得功能确实强大,也知道为什么阿里巴巴的前端传到github上的文件为啥都有一个 .idea 文件,(传说淘宝内部推荐写js用we ...
- Java基础面试题及答案(二)
容器 18. java 容器都有哪些? 常用容器的图录: 19. Collection 和 Collections 有什么区别? java.util.Collection 是一个集合接口(集合类的一个 ...
- Android PhotoView基本功能实现
Android开发过程中,想必都使用过PhotoView来实现图片展示的功能.在最新版的sdk(android-23)有了一个原生的photoView,并且代码实现也很简单,逻辑也很清晰.我们在实际的 ...
- 洛谷上的C语言三连击。
注意看题目,没有0,一直错. #include<stdio.h> int panduan1(int num1,int num2, int num3); int main(){ int i, ...
- VUE的中v-if和v-shou的区别
v-if的特点:每次都会重新删除或创建元素 v-shou的特点:每次执行都只是切换了元素的display:none的属性 v-if的缺点: 每次使用都会有较高性能消耗(频繁的切换元素建议不适用,建议使 ...
- Linux基础命令小技巧
总结 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux发行版之一,它是来自于Red Hat Enterprise L ...