A1337 | [COCI-2016_2017-contest1]#4 Mag
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
You are given an undirected tree with each of its node assigned a magic Xi .
1 The magic of a path is defined as the product of the magic of the nodes on that path divided 2 by the number of the nodes on the path. For example, the magic of a path that consists of nodes with magic 3 and 5 is
7.5 (3·5 / 2).
In the given tree, find the path with the minimal magic and output the magic of that path.
1 The magic of a path is defined as the product of the magic of the nodes on that path divided 2 by the number of the nodes on the path. For example, the magic of a path that consists of nodes with magic 3 and 5 is
7.5 (3·5 / 2).
In the given tree, find the path with the minimal magic and output the magic of that path.
输入格式
The first line of input contains the integer N (1 ≤ N ≤ 106 ), the number of nodes in the tree.
Each of the following N - 1 lines contains two integers, Ai and Bi (1 ≤ Ai , Bi ≤ N), the labels of nodes connected with an edge.
The i th of the following N lines contains the integer Xi (1 ≤ Xi ≤ 109 ), magic of the i th node.
Each of the following N - 1 lines contains two integers, Ai and Bi (1 ≤ Ai , Bi ≤ N), the labels of nodes connected with an edge.
The i th of the following N lines contains the integer Xi (1 ≤ Xi ≤ 109 ), magic of the i th node.
输出格式
Output the magic of the path with minimal magic in the form of a completely reduced fraction P/Q (P and Q are relatively prime integers).
In all test cases, it will hold that the required P and Q are smaller than 1018 .
In all test cases, it will hold that the required P and Q are smaller than 1018 .
输入输出样例
输入 #1
2 1 2 3 4
输出 #1
3/1
输入 #2
5 1 2 2 4 1 3 5 2 2 1 1 1 3
输出 #2
1/2
In test cases worth 24 points total, it will hold N ≤ 1 000.
In test cases worth 36 additional points total, there will not be a node that is connected to
more than 2 other nodes.
Clarification of the first test case: Notice that the path may begin and end in the same node. The path with the minimal magic consists of
the node with magic 3, so the entire path’s magic is 3 / 1.
Clarification of the second test case: The path that consists of nodes with labels 2 and 4 is of magic (1·1) / 2 = 1 / 2.
That is also the path with the minimal possible magic.
In test cases worth 36 additional points total, there will not be a node that is connected to
more than 2 other nodes.
Clarification of the first test case: Notice that the path may begin and end in the same node. The path with the minimal magic consists of
the node with magic 3, so the entire path’s magic is 3 / 1.
Clarification of the second test case: The path that consists of nodes with labels 2 and 4 is of magic (1·1) / 2 = 1 / 2.
That is also the path with the minimal possible magic.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted