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 ...
随机推荐
- linux下编译安卓ffmpeg
本次编译属于2013年6月项目的一部分,重新修改使用. 为统一工程版本 ffmpeg版本为1.2.1 本次的目录结构为 工程目录/jni/Android.mk 工程目录/jni/Application ...
- puppet案例
实例一.文件分发描述:通过puppet服务端可以向被管理机(客户端)上推送文件,方法是使用file类型的source属性 第一步:#vi /etc/puppet/fileserver.conf 1 ...
- 程序员需要掌握哪些IT技能
据Foote Partners的最新调查:如今,你掌握的 IT 技能的多少决定了你薪资的多少,但你不一定非要比开源架构师或Certified Secure Software Life Cycle Pr ...
- poj 1236 Network of Schools【强连通求孤立强连通分支个数&&最少加多少条边使其成为强连通图】
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13800 Accepted: 55 ...
- Java开发中常见的危险信号(中)
本文来源于我在InfoQ中文站原创的文章,原文地址是:http://www.infoq.com/cn/news/2013/12/common-red-flags-in-java-1 Dustin Ma ...
- Kinect for Windows SDK开发入门(一):开发环境配置
[译]Kinect for Windows SDK开发入门(一):开发环境配置 前几天无意中看到微软发布了Kinect for windows sensor,进去看了一下Kinect应用的例子,发现K ...
- 动态调用DLL函数有时正常,有时报Access violation的异常
动态调用DLL函数有时正常,有时报Access violation的异常 typedef int (add *)(int a,int b); void test() { hInst=LoadL ...
- js返回上一页方法区别
history.back(-1):直接返回当前页的上一页,数据全部消息,是个新页面 history.go(-1):也是返回当前页的上一页,不过表单里的数据全部还在
- mongodb的地理位置索引
mongoDB支持二维空间索引,使用空间索引,mongoDB支持一种特殊查询,如某地图网站上可以查找离你最近的咖啡厅,银行等信息.这个使用mongoDB的空间索引结合特殊的查询方法很容易实现.前提条件 ...
- 【转】coco2d-x 纹理研究
1.通常情况下用PVR格式的文件来进行图片显示的时候,在运行速度和内存消耗方面都要比PNG格式要快和小.一般情况下PVR消耗的内存比PNG消耗的内存小25%左右.PVR格式可以用ZWoptex导出.P ...