E. Ciel the Commander

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

Input

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.

Output

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

Examples

Input

4
1 2
1 3
1 4

Output

A B B B

Input

10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10

Output

D C B A D C B D C D

Note

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.

这个题,我真的不知道什么是点分治。

我们就题论题,这个题说要是点分治我不太懂,但是这个题我的思路很简单。这个题题意是说给一棵树,子节点的级别相同的时父节点的级别一定是高于他们的。开始是这么理解的,但是后来我发现不是这么回事,放两张图大家理解一下。就明白为什么每次都需要找重心了。

一开始我想的是这样:

但是后来我发现如果是这种情况的话:

只有这样才能把节点使用的最少进而达到题目要求。

#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
const int maxn=100005;
int vis[maxn],son[maxn],f[maxn],sum,root,ans[maxn];
vector<int> E[maxn];
void dfsroot(int x,int fa)
{
son[x]=1;f[x]=0;
for(int i=0;i<E[x].size();i++)
{
int v = E[x][i];
if(v == fa || vis[v])continue;
dfsroot(v,x);
son[x]+=son[v];
f[x]=max(f[x],son[v]);
}
f[x]=max(f[x],sum-son[x]);
if(f[x]<f[root])root=x;
}//找树的重心
void work(int x,int fa,int dep)
{
ans[x]=dep;
vis[x]=1;
for(int i=0;i<E[x].size();i++)
{
int v = E[x][i];
if(vis[v])continue;
sum=son[v],root=0;
dfsroot(v,x);
work(root,x,dep+1);
}
}//染色
int main()
{
int n;
scanf("%d",&n);
for(int i=1,x,y;i<n;i++)
{
scanf("%d%d",&x,&y);
E[x].push_back(y);
E[y].push_back(x);
}
f[0]=sum=n;
dfsroot(1,0);
work(root,0,0);
for(int i=1;i<=n;i++)
printf("%c ",ans[i]+'A');
printf("\n");
return 0;
}

Codeforce 322E Ciel the Commander (点分治)的更多相关文章

  1. CF 322E - Ciel the Commander 树的点分治

    树链剖分可以看成是树的边分治,什么是点分治呢? CF322E - Ciel the Commander 题目:给出一棵树,对于每个节点有一个等级(A-Z,A最高),如果两个不同的节点有相同等级的父节点 ...

  2. Codeforces Round #190 (Div. 2) E. Ciel the Commander 点分治

    E. Ciel the Commander Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest ...

  3. Codeforces G. Ciel the Commander

    题目描述: Ciel the Commander time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. CodeForces 321C Ciel the Commander

    Ciel the Commander Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...

  5. Ciel the Commander CodeForces - 321C (树, 思维)

    链接 大意: 给定n结点树, 求构造一种染色方案, 使得每个点颜色在[A,Z], 且端点同色的链中至少存在一点颜色大于端点 (A为最大颜色) 直接点分治即可, 因为最坏可以涂$2^{26}-1$个节点 ...

  6. [CF321C]Ciel the Commander

    题目大意: 给你一棵n个结点的树,给每个结点分级,最高为'A',最低为'Z'. 尝试构造一种分级方案,使得任意两个相同级别的结点路径上至少有一个更高级的结点. 思路: 贪心+树上点分. 递归处理每一棵 ...

  7. 树上的构造 树分治+树重心的性质 Codeforces Round #190 (Div. 2) E

    http://codeforces.com/contest/322/problem/E E. Ciel the Commander time limit per test 1 second memor ...

  8. Codeforces Round #190 (Div. 1 + Div. 2)

    A. Ciel and Dancing 模拟. B. Ciel and Flowers 混合类型的数量只能为0.1.2,否则3个可以分成各种类型各自合成. C. Ciel and Robot 考虑一组 ...

  9. 点分治 (等级排) codeforces 321C

    Now Fox Ciel becomes a commander of Tree Land. Tree Land, like its name said, has n cities connected ...

随机推荐

  1. 【Selenium01篇】python+selenium实现Web自动化:搭建环境,Selenium原理,定位元素以及浏览器常规操作!

    一.前言 最近问我自动化的人确实有点多,个人突发奇想:想从0开始讲解python+selenium实现Web自动化测试,请关注博客持续更新! 二.话不多说,直接开干,开始搭建自动化测试环境 这里以前在 ...

  2. CARS: 华为提出基于进化算法和权值共享的神经网络结构搜索,CIFAR-10上仅需单卡半天 | CVPR 2020

    为了优化进化算法在神经网络结构搜索时候选网络训练过长的问题,参考ENAS和NSGA-III,论文提出连续进化结构搜索方法(continuous evolution architecture searc ...

  3. Scala——的并行集合

    当出现Kafka单个分区数据量很大,但每个分区的数据量很平均的情况时,我们往往采用下面两种方案增加并行度: l  增加Kafka分区数量 l  对拉取过来的数据执行repartition 但是针对这种 ...

  4. hive常用函数五

    复合类型构建操作 1. Map类型构建: map 语法: map (key1, value1, key2, value2, …) 说明:根据输入的key和value对构建map类型 举例: hive& ...

  5. iOS技能 - 最新美团、百度、腾讯、头条、阿里 面试题目记录

    关于面试题,可能没那么多时间来总结答案,有什么需要讨论的地方欢迎大家指教.主要记录一下准备过程,和面试的一些总结,希望能帮助到正在面试或者将要面试的同学吧. 美团 一面 1.简历上写的项目问了一遍,然 ...

  6. .NET Core技术研究-主机

    前一段时间,和大家分享了 ASP.NET Core技术研究-探秘Host主机启动过程 但是没有深入说明主机的设计.今天整理了一下主机的一些知识,结合先前的博文,完整地介绍一下.NET Core的主机的 ...

  7. vueCli 运行报错

    error 如下: npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! shopping@0.1.0 serve: `vue-cli-service ...

  8. BFC的理解与应用

    什么是BFC(Block formatting contexts) BFC的通俗理解: 首先BFC是一个名词,是一个独立的布局环境,我们可以理解为一个箱子(实际上是看不见摸不着的),箱子里面物品的摆放 ...

  9. 实例讲解Springboot整合MongoDB进行CRUD操作的两种方式

    1 简介 Springboot是最简单的使用Spring的方式,而MongoDB是最流行的NoSQL数据库.两者在分布式.微服务架构中使用率极高,本文将用实例介绍如何在Springboot中整合Mon ...

  10. 【three.js第五课】光线的添加和感光材料

    材料分类: MeshBasicMaterial:基础网孔材料,一个以简单着色(平面或线框)方式来绘制几何形状的材料.MeshLambertMaterial:兰伯特网孔材料,一种非发光材料(兰伯特)的表 ...