首页 技术 正文
技术 2022年11月13日
0 收藏 691 点赞 2,519 浏览 4054 个字

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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,989
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,504
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,131
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,842