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 ...
随机推荐
- Python 函数知识点整理
- vue3.0wactch监听
<template> <div> <input v-model="count" /> </div> </template> ...
- 将Swagger2文档导出为HTML或markdown等格式离线阅读
网上有很多<使用swagger2构建API文档>的文章,该文档是一个在线文档,需要使用HTTP访问.但是在我们日常使用swagger接口文档的时候,有的时候需要接口文档离线访问,如将文档导 ...
- 高德JS依赖分析工程及关键原理
一.背景 高德 App 进行 Bundle 化后,由于业务的复杂性,Bundle 的数量非常多.而这带来了一个新的问题——Bundle 之间的依赖关系错综复杂,需要进行管控,使 Bundle 之间的依 ...
- 设计模式——代理模式(Proxy)
定义 为其他对象提供一种代理,以控制对这个对象的访问.代理对象在客户端和目标对象之间起到中介的作用.(结构型) 如果不知道代理模式,可能大家对代理服务器都不叫熟悉.代替服务器代替请求者去发一起对另一个 ...
- ReactRouter中HashRouter和BrowserRouter的区别
仅个人理解,如有不当请指正 一.从原理上 HashRouter在路径中包含了#,相当于HTML的锚点定位.(# 符号的英文叫hash,所以叫HashRouter,和散列没关系哦)) 而BrowserR ...
- Spring 框架基础(05):事务管理机制,和实现方式
本文源码:GitHub·点这里 || GitEE·点这里 一.Spring事务管理 1.基础描述 Spring事务管理的本质就是封装了数据库对事务支持的操作,使用JDBC的事务管理机制,就是利用jav ...
- Scheme实现数字电路仿真(1)——组合电路
EDA是个很大的话题,本系列只针对其中一小部分,数字电路的仿真,叙述一点概念性的东西,并不会过于深入,这方面的内容实则是无底洞.本系列并不是真的要做EDA,按照SICP里的相关内容,采用Lisp的方言 ...
- 用Python调用华为云API接口发短信
[摘要] 用Python调用华为云API接口实现发短信,当然能给调用发短信接口前提条件是通过企业实名认证,而且有一个通过审核的短信签名,话不多说,showcode #!/usr/bin/python3 ...
- 一统江湖的大前端(8)- velocity.js 运动的姿势(上)
[摘要] 介绍CSS动画和JS动画的基本特点,以及轻量级动画库velocity.js的基本用法. 示例代码托管在:http://www.github.com/dashnowords/blogs 博客园 ...