Poj 1511 Invitation Cards(spfa)
Invitation Cards
Time Limit: 8000MS Memory Limit: 262144K
Total Submissions: 24460 Accepted: 8091
Description
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessary information and with the programme. A lot of students were hired to distribute these invitations among the people. Each student volunteer has assigned exactly one bus stop and he or she stays there the whole day and gives invitation to people travelling by bus. A special course was taken where students learned how to influence people and what is the difference between influencing and robbery.
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
The input consists of N cases. The first line of the input contains 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
For each case, print one line containing the minimum amount of money to be paid each day by ACM for the travel costs of its volunteers.
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
Source
Central Europe 1998/有道翻译2.0/
邀请卡
时间限制: 8000毫秒 内存限制: 262144 k
总提交: 24460 接受: 8091
描述
在电视时代,没有多少人参加戏剧表演。 古董的喜剧演员Malidinesia意识到了这个事实。 他们想戏剧和传播,最重要的是,古董喜剧。 他们已经印刷请柬与所有必要的信息和计划。 很多学生在民间被雇来分配这些邀请。 每个学生志愿者分配一个公共汽车站,他或她呆一整天,邀请人们乘公共汽车旅行。 一个特殊的课程,学生学会了如何影响人们和影响和抢劫的区别是什么。
交通系统非常特别:所有行单向和连接两个停止。 公共汽车离开原始停止与乘客每半个小时。 到达目的地后停止他们空返回给源停止,他们等到下一个完整的半小时,例如X:00或X:30,“X”表示一个小时。 两个站之间的运输费用是由特殊的表和当场支付。 行计划以这样一种方式,每个往返(即一段旅程开始和结束在同一停止)通过一个中央检查站停止(CCS),每个乘客都有通过彻底的检查包括身体扫描。
所有ACM学生成员离开CCS每天早上。 每个志愿者是搬到一个预先确定的停止邀请乘客。 有尽可能多的志愿者们停止。 在一天结束的时候,所有的学生都回到CCS。 你要编写一个计算机程序,帮助ACM最小化的资金支付每天员工的交通。
输入
输入包含N情况下。 输入的第一行包含唯一的正整数n .然后按照病例。 每个案例始于一行包含两个整数P和Q,1 < = P,Q < = 1000000。 P是停止的数量包括CCS和公交线路的数量。 还有问行,每个描述一个总线。 每个行包含三个数字——原始停止,目的地停止和价格。 指定的CCS是1号。 价格是正整数之和小于1000000000。 你也可以认为它总是可以从任何停止其他停止。
输出
对于每个案例,打印一行包含最少的钱来支付每天ACM旅行费用的志愿者。
样例输入
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
样例输出
46
210
源
1998年欧洲中部
/*
邻接链表+spfa.
正反两边spfa.
ans为两次1点到所有点的最小费用.
建图的时候反边即可.
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define MAXN 1000001
using namespace std;
long long tot;
int n,m,head[MAXN],dis[MAXN],x[MAXN],y[MAXN],z[MAXN],cut;
bool b[MAXN];
struct data
{
int v;
int z;
int next;
}e[MAXN];
void add(int u,int v,int z)
{
e[cut].z=z;
e[cut].v=v;
e[cut].next=head[u];
head[u]=cut++;
}
void spfa()
{
int u;
queue<int>q;
q.push(1);b[1]=true;dis[1]=0;
while(!q.empty())
{
u=q.front();
q.pop();
for(int i=head[u];i!=-1;i=e[i].next)
{
int v=e[i].v;
if(e[i].z+dis[u]<dis[v])
{
dis[v]=e[i].z+dis[u];
if(!b[v])
{
b[v]=true;
q.push(v);
}
}
}
}
}
void init()
{
cut=0;
memset(e,0,sizeof(e));
memset(dis,0x7f,sizeof(dis));
memset(head,-1,sizeof(head));
memset(b,0,sizeof(b));
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
tot=0;
init();
//printf("%d",dis[1]);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x[i],&y[i],&z[i]);
add(x[i],y[i],z[i]);
}
spfa();
for(int i=1;i<=n;i++)
tot+=dis[i];
init();
for(int i=1;i<=m;i++)
{
add(y[i],x[i],z[i]);//反边.
}
spfa();
for(int i=1;i<=n;i++)
tot+=dis[i];
printf("%lld\n",tot);
}
return 0;
}
Poj 1511 Invitation Cards(spfa)的更多相关文章
- POJ 1511 Invitation Cards (spfa的邻接表)
Invitation Cards Time Limit : 16000/8000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) ...
- poj 1511 Invitation Cards spfa 邻接矩阵
题目链接: http://poj.org/problem?id=1511 题目大意: 这道题目比较难理解,我读了好长时间,最后还是在队友的帮助下理解了题意,大意就是,以一为起点,求从一到其他各点的最短 ...
- 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 (最短路spfa)
Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...
- (简单) POJ 1511 Invitation Cards,SPFA。
Description In the age of television, not many people attend theater performances. Antique Comedians ...
- POJ 1511 Invitation Cards 链式前向星+spfa+反向建边
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 27200 Accepted: 902 ...
- SPFA算法(2) POJ 1511 Invitation Cards
原题: Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 31230 Accepted: ...
- POJ 1511 Invitation Cards(逆向思维 SPFA)
Description In the age of television, not many people attend theater performances. Antique Comedians ...
- [POJ] 1511 Invitation Cards
Invitation Cards Time Limit: 8000MS Memory Limit: 262144K Total Submissions: 18198 Accepted: 596 ...
随机推荐
- Camera图像处理原理及实例分析-重要图像概念
Camera图像处理原理及实例分析 作者:刘旭晖 colorant@163.com 转载请注明出处 BLOG:http://blog.csdn.net/colorant/ 主页:http://rg ...
- 伪分布配置完成启动jobtracker和tasktracker没有启动
检查logs目录下的hadoop-root-jobtracker日志文件 2014-02-26 19:56:06,782 FATAL org.apache.hadoop.mapred.JobTrack ...
- Web Service学习文旦下载
Web Service的学习暂且告一段落,因为毕竟只是对它作简要了解,至于其原理什么并不打算涉及. 在这里我提供下我之前文档的整理版本: http://kuai.xunlei.com/d/YlzvAG ...
- 无法通过 128 (在表空间 TEMP 中) 扩展 temp 段
1.查看表空间中数据文件存储的路径以及是否可以自动扩展 SELECT TABLESPACE_NAME, BYTES/1024/1024 FILE_SIZE_MB, FILE_NAME FROM DBA ...
- 第三步 用Jena自定义完成数据库到RDF的映射
第三步 用Jena自定义完成数据库到RDF的映射 2013年10月17日 8:53:27 这一步用Jena编程,终于能做点有技术含量的事情了.这个工作计划本周内完成,下周一好给老师一个交待. 目标:把 ...
- eclipse 插件之Code Folding
功能: eclipse自带折叠包括方法, import, 注释等得折叠功能, code folding 插件对其增强. 1. 下载插件:( 也可以用link方式, 我的是link安装, jar包网上很 ...
- 10409 - Die Game
Problem G: Die Game Life is not easy. Sometimes it is beyond your control. Now, as contestants of AC ...
- Effective Java:Ch4_Class:Item13_最小化类及其成员的可访问性
要区别一个模块是否设计良好,最重要的因素是,对于其他模块而言该模块隐藏其内部数据和其他实现细节的程度.设计良好的模块应该隐藏所有实现细节,将API与其实现清晰地隔离开来.这样,模块之间通过他们的API ...
- 理解 MEF
1.它解决什么问题? 考虑下面的需求,甲程序员对外暴露接口,内部提供实现.乙程序员使用甲提供的接口,根据面向接口编程的原则,乙关联一个接口类型的引用.正常情况下,乙要使用甲的实现,必须实例化一个具体对 ...
- FormMove
private { Private declarations } procedure WMMOVE(var Msg: TMessage); message WM_MOVE; proced ...