A9162 | Ciel the Commander
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has $n$ cities connected by $n-1$ undirected roads, and for any two cities there always exists a path between them.
Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 different ranks, and 'A' is the topmost, so 'Z' is the bottommost.
There are enough officers of each rank. But there is a special rule must obey: if $x$ and $y$ are two distinct cities and their officers have the same rank, then on the simple path between $x$ and $y$ there must be a city $z$ that has an officer with higher rank. The rule guarantee that a communications between same rank officers will be monitored by higher rank officer.
Help Ciel to make a valid plan, and if it's impossible, output "Impossible!".
Fox Ciel needs to assign an officer to each city. Each officer has a rank — a letter from 'A' to 'Z'. So there will be 26 different ranks, and 'A' is the topmost, so 'Z' is the bottommost.
There are enough officers of each rank. But there is a special rule must obey: if $x$ and $y$ are two distinct cities and their officers have the same rank, then on the simple path between $x$ and $y$ there must be a city $z$ that has an officer with higher rank. The rule guarantee that a communications between same rank officers will be monitored by higher rank officer.
Help Ciel to make a valid plan, and if it's impossible, output "Impossible!".
输入格式
The first line contains an integer $n$ ( $2<=n<=10^{5}$ ) — the number of cities in Tree Land.
Each of the following $n-1$ lines contains two integers $a$ and $b$ ( $1<=a,b<=n,a≠b$ ) — they mean that there will be an undirected road between $a$ and $b$ . Consider all the cities are numbered from 1 to $n$ .
It guaranteed that the given graph will be a tree.
Each of the following $n-1$ lines contains two integers $a$ and $b$ ( $1<=a,b<=n,a≠b$ ) — they mean that there will be an undirected road between $a$ and $b$ . Consider all the cities are numbered from 1 to $n$ .
It guaranteed that the given graph will be a tree.
输出格式
If there is a valid plane, output $n$ space-separated characters in a line — $i$ -th character is the rank of officer in the city with number $i$ .
Otherwise output "Impossible!".
Otherwise output "Impossible!".
输入输出样例
输入 #1
4 1 2 1 3 1 4
输出 #1
A B B B
输入 #2
10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
输出 #2
D C B A D C B D C D
In the first example, for any two officers of rank 'B', an officer with rank 'A' will be on the path between them. So it is a valid solution.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted