300560: CF107A. Dorm Water Supply

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Dorm Water Supply

题意翻译

给出一组 $n$ 个点,$m$ 条边的有向图,边带权。保证每个点的出度和入度最多为 $1$ 对于每一个入度为 $0$,出度为 $1$ 的点,我们在该点建一个水箱 对于每一个入度为 $1$,出度为 $0$ 的点,我们在该点建一个水龙头 可以发现,每一个水箱对应一个唯一的水龙头,我们将每对对应的水龙头和水箱称为一个 水器组 请求出每一个水箱到他对应的水龙头的路径上的边权最小值 ### 输入格式 第一行两个整数 $n,m$,分别表示点数和边数 接下来 $m$,行,每行三个整数 $u,v,len$ 表示有一条 $u$ 指向 $v$ 的,长度为 $len$ 的有向边 ### 输出格式 第一行一个整数 $k$,表示水器组的个数 接下来 $k$ 行,每行三个正整数 $x,y,c$ ,$(x \ne y)$ ,表示一对水器组:$x$ 为水箱所在节点, $y$ 为水龙头所在节点,$c$ 为 $x$ 到 $y$ 的路径上的边权最小值 **说明与提示** $1 \le n \le 1000$ $0 \le m \le n$ 边权不超过 $10^6$ 注意水龙头和水箱不能建在同一个节点上 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

题目描述

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.

输入输出格式

输入格式


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}<=10^{6} $ ). 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.

输出格式


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} $ .

输入输出样例

输入样例 #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

Input

题意翻译

给出一组 $n$ 个点,$m$ 条边的有向图,边带权。保证每个点的出度和入度最多为 $1$ 对于每一个入度为 $0$,出度为 $1$ 的点,我们在该点建一个水箱 对于每一个入度为 $1$,出度为 $0$ 的点,我们在该点建一个水龙头 可以发现,每一个水箱对应一个唯一的水龙头,我们将每对对应的水龙头和水箱称为一个 水器组 请求出每一个水箱到他对应的水龙头的路径上的边权最小值 ### 输入格式 第一行两个整数 $n,m$,分别表示点数和边数 接下来 $m$,行,每行三个整数 $u,v,len$ 表示有一条 $u$ 指向 $v$ 的,长度为 $len$ 的有向边 ### 输出格式 第一行一个整数 $k$,表示水器组的个数 接下来 $k$ 行,每行三个正整数 $x,y,c$ ,$(x \ne y)$ ,表示一对水器组:$x$ 为水箱所在节点, $y$ 为水龙头所在节点,$c$ 为 $x$ 到 $y$ 的路径上的边权最小值 **说明与提示** $1 \le n \le 1000$ $0 \le m \le n$ 边权不超过 $10^6$ 注意水龙头和水箱不能建在同一个节点上 感谢 @[_Wolverine](https://www.luogu.com.cn/user/120362) 提供的翻译

加入题单

算法标签: