INCARDS - Invitation Cards

题意翻译

演员们雇了很多很多的学生来散发传单。每一个学生都负责一个公交车站。交通系统所有的线路都是单向的并且连接两个车站。 每半个小时,就会有一辆载有乘客的公交车从起点站出发。到达终点站之后,所有的公交车都会在空车的状态下返回那个等待了半个小时的车站,并且继续出发,例如从 $X:00$ 到 $X:30$,其中 $X$ 表示时间的小时部分。在两个车站之间来往的车票票价会在表格中给出,并且可以在并且可以在车站支付。交通路线经过精心设计,使得每一个环路(即起点和重点相同的路线)都会经过一个检查点(CCS)。 所有的学生志愿者们每天早上从 CCS 出发,所有人都会去预先定好的公交车站散发传单,车站数量和学生数量相等。 每天晚上,所有的学生坐车回到 CCS。你的任务是:编写一个程序,计算所有学生的交通费总和的最小值。 ### 输入格式 第一行包含一个整数 $N$,代表数据的组数。 对于每组数据,第一行包含两个整数 $P$ 和 $Q$。$P$ 是包含 CCS 的线路数量,$Q$ 是公交线路的总数。 接下来有 $Q$ 行,每一行都包含三个整数 $u_i,v_i,w_i$,表示一条公交线路。 其中,$u_i$ 和 $v_i$ 分别表示公交的起始和终点站,$w_i$ 表示这条公交线路的票价,CCS 的代表数字是 $1$。 ### 输出格式 对于每一组数据,输出一行表示所有学生的交通费总和的最小值。 ### 数据范围与约定 $1 \le P,Q \le 10 ^ 6, \sum w_i \le 10 ^ 9$。 数据保证任意两个车站之间有至少一条路线可以互相到达。

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

输入输出样例

输入样例 #1

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

输出样例 #1

46
210

说明

**Warning: large Input/Output data, be careful with certain languages**