A8206 | Dorm Water Supply
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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}$ .
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted