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. makefile for VCS from Syn@psys

    已调试通过 未来将修改成verdi的FSDB版本 下载后把 Makefile_VCS.txt 修改为 Makefile 就可以使用 链接地址: http://files.cnblogs.com/all ...

  2. PLSQL配置介绍

    PLSQL配置简介,优化   来自为知笔记(Wiz) 附件列表 s=selectf=FROMw=WHEREsf=SELECT * FROMdf=DELETE FROMsc=SELECT COUNT(* ...

  3. 混合模式程序集是针对“v1.1.4322”版的执行时生成的,在没有配置其它信息的情况下,无法在 4.0 执行时中载入该程序集。

    看到一个kinect大牛编写的一个水果忍者的体感游戏版本号,让我为自己一直以来仅仅用现有的网页游戏来模拟kinect体感游戏控制感到羞愧,没办法.我还是菜鸟.学习一段后自己模仿星际大战这个游戏.自己写 ...

  4. Static NAT with iptables on Linux

    本文的名字取的比较有意义,因为本文并不是真的要讨论如何在Linux上使用iptables实现static nat!之所以这么命名本文,是想引起别人的注意,因为中文资料,以及国内的搜索引擎,基本上没有人 ...

  5. paip. mysql如何临时 暂时 禁用 关闭 触发器

    paip. mysql如何临时 暂时 禁用 关闭 触发器 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn ...

  6. Bluetooth 4.0之Android 讲解

    Android平台包含了对蓝牙网络协议栈的支持,它允许一个蓝牙设备跟其他的蓝牙设备进行无线的数据交换.应用程序通过Android蓝牙API提供访问蓝牙的功能.这些API会把应用程序无线连接到其他的蓝牙 ...

  7. 【转】BeagleBone Black USB一线通(3)

    接上篇  BeagleBone Black 一线通(2) 五.vnc图形终端 虽然 BB-Black带有一个Micro-HDMI接口,不过那么名片不到的一个小板,连接到一个20来寸的显示器上,还是有些 ...

  8. 使用ExpandableListView实现一个时光轴

    在许多App上都能看到时光轴的效果,比如携程等等,那么我们今天就利用ExpandableListView来实现一个时光轴效果,先来看看效果图: 效果还是挺简单的,这里我们主要是采用Expandable ...

  9. Java基础知识强化之IO流笔记46:IO流练习之 把文本文件中数据存储到集合中的案例

    1.  把文本文件中数据存储到集合中      需求:从文本文件中读取数据(每一行为一个字符串数据)到集合中,并遍历集合. 分析:      通过题目的意思我们可以知道如下的一些内容,      数据 ...

  10. Java基础知识强化之集合框架笔记72:集合特点和数据结构总结

    1. 集合 (1)Collection(单列集合) List(有序,可重复):                         ArrayList:底层数据结构是数组,查询块,增删慢.线程不安全,效率 ...