CF107A.Dorm Water Supply
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).
For each house, there is at most one pipe going into it and at most one pipe going out of it. With the new semester starting, GUC student and dorm resident, Lulu, wants to install tanks and taps at the dorms. For every house with an outgoing water pipe and without an incoming water pipe, Lulu should install a water tank at that house. For every house with an incoming water pipe and without an outgoing water pipe, Lulu should install a water tap at that house. Each tank house will convey water to all houses that have a sequence of pipes from the tank to it. Accordingly, each tap house will receive water originating from some tank house.
In order to avoid pipes from bursting one week later (like what happened last semester), Lulu also has to consider the diameter of the pipes. The amount of water each tank conveys should not exceed the diameter of the pipes connecting a tank to its corresponding tap. Lulu wants to find the maximal amount of water that can be safely conveyed from each tank to its corresponding tap.
德国开罗大学(GUC)的学生宿舍编号从 1 到 n。地下水管将这些宿舍相互连接。每根水管具有特定的方向(水仅能沿该方向流动,不可反向流动)和直径(表征其可承载的最大水量)。
对每个宿舍而言,至多有一根水管流入,且至多有一根水管流出。随着新学期开始,GUC 学生兼宿舍住户 Lulu 计划在宿舍中安装水箱和水龙头。对于每栋拥有向外水管但无向内水管的宿舍,Lulu 应在该宿舍安装一个水箱;对于每栋拥有向内水管但无向外水管的宿舍,Lulu 应在该宿舍安装一个水龙头。每个水箱宿舍将通过一系列水管向所有可从该水箱经水管序列到达的宿舍供水。相应地,每个水龙头宿舍将接收来自某个水箱宿舍的水。
为避免水管一周后爆裂(如同上学期所发生的那样),Lulu 还必须考虑水管的直径。每个水箱所输送的水量不得超过连接该水箱与其对应水龙头的所有水管的直径。Lulu 希望求出每个水箱到其对应水龙头之间可安全输送的最大水量。
输入格式
The first line contains two space-separated integers n and p (1 ≤ n ≤ 1000, 0 ≤ p ≤ n) — the number of houses and the number of pipes correspondingly.
Then p lines follow — the description of p pipes. The i-th line contains three integers a__i b__i d__i, indicating a pipe of diameter d__i going from house a__i to house b__i (1 ≤ a__i, b__i ≤ n, a__i ≠ b__i, 1 ≤ d__i ≤ 106).
It is guaranteed that for each house there is at most one pipe going into it and at most one pipe going out of it.
第一行包含两个以空格分隔的整数 n 和 p(1≤n≤1000,0≤p≤n)—— 分别表示房屋的数量和管道的数量。
接下来是 p 行,描述这 p 条管道。第 i 行包含三个整数 ai、bi、di,表示一条直径为 di 的管道,从房屋 ai 连接到房屋 bi(1≤ai,bi≤n,ai=bi,1≤di≤106)。
保证对于每座房屋,至多有一条管道流入,且至多有一条管道流出。
输出格式
Print integer t in the first line — the number of tank-tap pairs of houses.
For the next t lines, print 3 integers per line, separated by spaces: tank__i, tap__i, and diameter__i, where tank__i ≠ tap__i (1 ≤ i ≤ t). Here tank__i and tap__i are indexes of tank and tap houses respectively, and diameter__i is the maximum amount of water that can be conveyed. All the t lines should be ordered (increasingly) by tank__i.
第一行输出整数 t —— 表示水箱-水龙头房屋对的数量。
接下来的 t 行中,每行输出 3 个由空格分隔的整数:tanki、tapi 和 diameteri,其中 tanki=tapi(1≤i≤t)。这里 tanki 和 tapi 分别为水箱房屋和水龙头房屋的索引,而 diameteri 是可输送的最大水量。所有 t 行应按 tanki 的值升序排列。
输入输出样例
输入#1
3 2 1 2 10 2 3 20
输出#1
1 1 3 10
输入#2
3 3 1 2 20 2 3 10 3 1 5
输出#2
0
输入#3
4 2 1 2 60 3 4 50
输出#3
2 1 2 60 3 4 50
输入解题思路,AI测评打分。不知道怎么写?