题目名称 | 2468. [US open]Clear Cold Water |
---|---|
输入输出 | coldwat.in/out |
难度等级 | ☆ |
时间限制 | 1000 ms (1 s) |
内存限制 | 256 MiB |
测试数据 | 10 |
题目来源 | ZXCVBNM_1 于2016-09-17加入 |
开放分组 | 全部用户 |
提交状态 | |
分类标签 | |
分享题解 |
通过:1, 提交:1, 通过率:100% | ||||
ZXCVBNM_1 | 100 | 0.017 s | 2.21 MiB | C++ |
关于 Clear Cold Water 的近10条评论(全部评论) | ||||
---|---|---|---|---|
%%%
AntiLeaf
2016-09-21 12:24
1楼
|
The steamy, sweltering summers of Wisconsin's dairy district stimulate the cows to slake their thirst. Farmer John pipes clear cold water into a set of N (3 <= N <= 99999; N odd) branching pipes conveniently numbered 1..N from a pump located at the barn. As the water flows through the pipes, the summer heat warms it. Bessie wants to find the coldest water so she can enjoy the weather more than any other cow.
She has mapped the entire set of branching pipes and noted that they form a tree with its root at the farm and furthermore that every branch point has exactly two pipes exiting from it. Surprisingly, every pipe is exactly one unit in length; of course, all N pipes connect up in one way or another to the pipe-tree.
Given the map of all the pipe connctions, make a list of the distance from the barn for every branching point and endpoint.Bessie will use the list to find the very coldest water.
The endpoint of a pipe, which might enter a branching point or might be a spigot, is named by the pipe's number. The map contains C (1 <= C <= N) connections, each of which specifies three integers: the endpoint E_i (1 <= E_i <= N) of a pipe and two branching pipes B1_i and B2_i (2 <= B1_i <= N; 2 <= B2_i <= N). Pipe number 1 connects to the barn; the distance from its endpoint to the barn is 1.
翻译:
闷热的夏天,威斯康辛州的奶制品地区提供冷水供奶牛饮用,以此来解渴。农夫约翰将冷水通过N (3 <= N <= 99999; N 为奇数)个冷水管道,分别编号序号1..N从泵的位置一直送到牛棚里。当水在管道中流动时,夏天的热能使它变热。贝茜想要找到最冷的水,这样她就能比任何其他奶牛更好地享受这难得的好天气。
她已经绘制了一整套完整的分支管道,并注意到这个管道系统犹如一棵树,它的根在农场,从根开始每个分支都分离出两个管道。令人惊讶的是,所有管道都有一个长度,当然这所有的N根管道连接成1条路或者和其他的管道路线连接。
给出所有管道连接的地图,计算每一个分支点到牛棚的距离。贝茜将通过这些信息来找到最清凉冷水。
管数1连接到谷仓,从它的端点到谷仓的距离是1。
*第 1 行: 2个用空格隔开的整数 N , C
* 第 2 至 C+1 行: 3个用空格隔开的整数,分别表示连接器的编号,以及连接的2个管道的编号E_i, B1_i, B2_i
* 共 N 行: 分别表示每个管道到牛棚的最短距离。
5 2 3 5 4 1 2 3
1 2 2 3 3
INPUT DETAILS:
The input above describes this pipe map:
+------+
| Barn |
+------+
| 1
*
2 / \ 3
*
4 / \ 5
OUTPUT DETAILS:
Pipe 1 is always distance 1 from the barn. Pipes 2 and 3 connect directly to pipe 1 and thus are distance 2 from the barn. Pipes 4 and 5, which connect to pipe 3, are distance 3 from the barn.
USACO Open 2008 Bronze