CF321C.Ciel the Commander

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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!".

现在,小狐狸Ciel成为了树国(Tree Land)的指挥官。顾名思义,树国由 nn 座城市组成,这些城市通过 n−1n-1 条无向道路相连;且任意两座城市之间都存在一条路径。

Ciel需要为每座城市指派一名军官。每名军官有一个军衔——即从 'A' 到 'Z' 的一个字母。因此共有 26 种不同军衔,其中 'A' 为最高军衔,'Z' 为最低军衔。

每种军衔的军官数量均充足。但必须遵守一条特殊规则:若 xx 和 yy 是两座不同的城市,且它们的军官军衔相同,则在 xx 与 yy 之间的简单路径上,必须存在一座城市 zz,其军官的军衔严格更高(即字母序更靠前)。该规则保证了同军衔军官之间的通信将被更高军衔的军官所监控。

请帮助Ciel制定一个合法的指派方案;若不存在合法方案,请输出 "Impossible!"。

输入格式

The first line contains an integer n (2 ≤ n ≤ 105) — 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.

第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5)—— 表示 Tree Land 中的城市数量。

接下来的 n−1n-1 行中,每行包含两个整数 aa 和 bb(1≤a,b≤n1 \leq a, b \leq n,且 a≠ba \neq b)—— 表示在城市 aa 与 bb 之间将修建一条无向道路。所有城市编号为 11 到 nn。

保证所给图是一棵树。

输出格式

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!".

如果存在一个有效的方案,输出一行包含 n 个空格分隔的字符——其中第 i 个字符表示编号为 i 的城市中军官的等级。

否则输出 "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.

在第一个例子中,对于任意两名等级为“B”的军官,都存在一名等级为“A”的军官位于他们之间的路径上。因此,这是一个有效的解。

输入解题思路,AI测评打分。不知道怎么写?

首页