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 ...
随机推荐
- 树莓派4B安装netcore
准备材料 SDFormatter.exe ---格式化SD卡,空的SD就可以不用了 2019-09-26-raspbian-buster.img ---下载好树莓派系统镜像 win32diskimag ...
- Flex修改皮肤样式
Flex修改皮肤大致有三种方式: (以button为例) 第一种:修改外观 1.flex项目中新建mxml外观.
- 扛把子组2018092609-2 选题 Scrum立会报告+燃尽图 04
此作业的要求参见[https://edu.cnblogs.com/campus/nenu/2019fall/homework/8682] 一.小组情况组长:迟俊文组员:宋晓丽 梁梦瑶 韩昊 刘信鹏队名 ...
- 基于Galera Cluster多主结构的Mysql高可用集群
Galera Cluster特点 1.多主架构:真正的多点读写的集群,在任何时候读写数据,都是最新的 2.同步复制:集群不同节点之间数据同步,没有延迟,在数据库挂掉之后,数据不会丢失 3.并发复制:从 ...
- 浅谈.NET中的反射
一.概述 1.通过反射可以提供类型信息,从而使得我们开发人员在运行时能够利用这些信息构造和使用对象 2.反射机制允许程序在执行过程中动态地添加各种功能 二.运行时类型标识 1.运行时类型标志(RTT ...
- 第三个视频作品《小白快速入门greenplum》上线了
1.场景描述 第三个视频作品出炉了,<小白快速入门greenplum>上线了,有需要的朋友可以直接点击链接观看.(如需购买,请通过本文链接购买) 2. 课程内容 课程地址:https:// ...
- Eclipse设置Working Set管理项目和detach合并分离窗口
当项目多了的时候,使用Working Set分组管理项目很有必要了,不然一大推项目在一起 找起来麻烦,看起来也难受~ 所以根据给项目不同分类就很有必要了. 之前myeclipse设置了,今天装了一 ...
- 洛谷P2670-扫雷游戏
文章目录 原题链接 题面简述 输入格式 输出格式 思路 代码 原题链接 题面简述 在n行m列的雷区中有一些格子含有地雷(称之为地雷格),其他格子不含地雷(称之为非地雷格).玩家翻开一个非地雷格时,该格 ...
- 浅谈Python中函数式编程、面向对象编程以及古怪的PythonIC
1.函数式编程作为结构化编程的一种,正在受到越来越多的重视.那么什么事函数式编程呢? 在维基百科中给出了详细的定义,函数式编程又称泛函数编程,是一种编程规范,它将函数运算视为数学上的函数计算.简单的来 ...
- 虚拟机中linux操作系统raid10(5块磁盘)配置流程及损坏磁盘的移除
打开所要用的虚拟机,点击编辑虚拟机设置,点击硬盘,添加 2.一直点击下一步不做修改,直到最后完成 3.按照以上步骤添加5块磁盘 4.点击开启虚拟机,输入用户名root密码登录进去 5.进入虚拟机后,鼠 ...