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)的更多相关文章

  1. POJ 1511 Invitation Cards (spfa的邻接表)

    Invitation Cards Time Limit : 16000/8000ms (Java/Other)   Memory Limit : 524288/262144K (Java/Other) ...

  2. poj 1511 Invitation Cards spfa 邻接矩阵

    题目链接: http://poj.org/problem?id=1511 题目大意: 这道题目比较难理解,我读了好长时间,最后还是在队友的帮助下理解了题意,大意就是,以一为起点,求从一到其他各点的最短 ...

  3. 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 / ...

  4. POJ 1511 Invitation Cards (最短路spfa)

    Invitation Cards 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/J Description In the age ...

  5. (简单) POJ 1511 Invitation Cards,SPFA。

    Description In the age of television, not many people attend theater performances. Antique Comedians ...

  6. POJ 1511 Invitation Cards 链式前向星+spfa+反向建边

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 27200   Accepted: 902 ...

  7. SPFA算法(2) POJ 1511 Invitation Cards

    原题: Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 31230   Accepted: ...

  8. POJ 1511 Invitation Cards(逆向思维 SPFA)

    Description In the age of television, not many people attend theater performances. Antique Comedians ...

  9. [POJ] 1511 Invitation Cards

    Invitation Cards Time Limit: 8000MS   Memory Limit: 262144K Total Submissions: 18198   Accepted: 596 ...

随机推荐

  1. MongoDB 入门之查询(find)

    MongoDB 入门之查询(find) 1. find 简介 (1)find的第一个参数决定了要返回哪些文档. 空的查询文档会匹配集合的全部内容.默认就是{}.结果将批量返回集合c中的所有文档. db ...

  2. 有关gcc的扩展__attribute__((unused))

    ================================ Author: taoyuetao Email: tao_yuetao@yahoo.com.cn Blog: taoyuetao.cu ...

  3. Go语言简介

    Go语言简介 - Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率. Go语言简介 Go语言是由Google开发的一个开源项目,目的之一为了提高开发人员的编程效率. Go ...

  4. Ⅹ.spring的点点滴滴--IObjectPostProcessor(对象后处理器)

    承接上文 IObjectPostProcessor(对象后处理器) 前提是实现接口的对象注册给当前容器 C#: 通过继承AbstractObjectFactory对象的AddObjectPostPro ...

  5. 单片微机原理P2:80C51外部中断与定时器系统

    0. 外部中断 书上的废话当然是很多的了,对于中断我想大家应该早就有一个很直观的认识,就是"设置断点,执行外部外码,然后返回断点"这样的三个过程.中断给系统提供了一个良好的响应模式 ...

  6. 来试试这个来自静态代码分析工具PVS Studio提供C++的小测验吧

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:来试试这个来自静态代码分析工具PVS Studio提供C++的小测验吧.

  7. IOS tableView 自定义cell 多行时 文字重复现象

    今天写了一个demo,有一个问题,有很多cell,但是超过一页后往下翻,发现文字有重叠现象, cell用的是重用机制,按说不会这样,最终解决的方案: 勾选这个,clears graphics cont ...

  8. Android中FTP服务器、客户端搭建以及SwiFTP、ftp4j介绍

    本文主要内容: 1.FTP服务端部署---- 基于Android中SwiFTP开源软件介绍: 2.FTP客户端部署 --- 基于ftp4j开源jar包的客户端开发 : 3.使用步骤 --- 如何测试我 ...

  9. Hdu 2473(并查集删除操作) Junk-Mail Filter

    有木有非常吊 加强 加强版   啊  ,看了都不敢做了   .后来先做了食物链这个我还是看过的.但还是A不掉,没明确神魔意思 .总而言之.大牛的博客是个好东西.我就那么看了一下,还是不懂怎莫办啊,哎, ...

  10. mysql 索引优化

    http://blog.jobbole.com/87107/ http://www.phpben.com/?post=74 http://blogread.cn/it/article/4088?f=s ...