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 ...
随机推荐
- PHP中Redis扩展无法加载问题
问题: 在重启php-fpm的过程中,发生了如下的错误,redis.so无法载入 1 2 3 4 [root@brand009 modules]# /usr/sbin/php-fpm /usr/sbi ...
- Nmap强大在哪之主机发现
1.概述 博主前段时间刚入坑渗透测试,随着学习的深入,越来越发现Nmap简直无所不能.今天先从主机发现功能入手分析. 2.Nmap主机发现 nmap --help #nmap帮助 3.参数分析 3.1 ...
- CentOS7中安装MariaDB
什么是mariaDB? 在线安装(慢的要命) RPM离线安装(CentOS7.X) 在线安装 打开官方网站 https://mariadb.org/ 点击Download,跳转到下一页面 继续点击Do ...
- 2019-11-19:无返回的盲型xxe,使用带外读取数据
文章资料来源于网络,仅供参考,学习使用 复现盲型xxe 实验环境:bwapp,xxe关,注释掉了返回值 准备读取的flag.txt文件为 通过利用服务器外带数据方法步骤 1,攻击机服务器新建两个文件, ...
- 微信小程序获取二维码(直接上代码)https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN
应为是直接返回二进制数据所有与其他接口些许差别,希望能帮助现在的你! 谢谢!!! /** * 37.微信二维码生成 */ public String getWeiXinCourseMap() { ...
- Java异常处理只有Try-Catch吗?
今天,我们将讨论一个非常重要的主题-Java 中的异常处理.尽管有时可能会对此主题进行过多的讨论,但并非每篇文章都包含有用且相关的信息. Java 中最常见的异常处理机制通常与 try-catch 块 ...
- 深入浅出Spring(三)
我为大家简单介绍了一下Spring框架核心内容中的IoC,接下来我们继续讲解另一个核心AOP(Aspect Oriented Programming),即面向切面编程. 1.OOP回顾 在介绍AOP之 ...
- 【JavaEE】之MyBatis动态SQL
动态SQL就是在SQL语句中添加一些标签,以完成某些逻辑.通常用到的动态SQL标签有<if>.<choose>.<where>.<trim>.<s ...
- Java多线程——锁
Java多线系列文章是Java多线程的详解介绍,对多线程还不熟悉的同学可以先去看一下我的这篇博客Java基础系列3:多线程超详细总结,这篇博客从宏观层面介绍了多线程的整体概况,接下来的几篇文章是对多线 ...
- c++ use curllib send REST API request to Web server
E.g and explaination: Pre-condition: Server is running and can reciever CURL command with json forma ...