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. *【2019牛客暑期多校训练营(第三场)- G】Removing Stones(分治)

    题干: 链接:https://ac.nowcoder.com/acm/contest/883/G 来源:牛客网 Summer vacation is coming and Mark has retur ...

  2. 分治算法的设计思想(二分检索、二分归并排序)

    分治策略思想: 将原问题划分或者归结为规模较小的子问题. 递归或迭代求解每一个问题. 将子问题的解综合得到原问题的解. 性质: 子问题与原问题具有相同的性质. 子问题的求解彼此独立. 划分时子问题的规 ...

  3. 【线段树分治 线性基】luoguP3733 [HAOI2017]八纵八横

    不知道为什么bzoj没有HAOI2017 题目描述 Anihc国有n个城市,这n个城市从1~n编号,1号城市为首都.城市间初始时有m条高速公路,每条高速公路都有一个非负整数的经济影响因子,每条高速公路 ...

  4. (2016北京集训十)【xsy1529】小Q与进位制 - 分治FFT

    题意很简单,就是求这个数... 其实场上我想出了分治fft的正解...然而不会打...然后打了个暴力fft挂了... 没啥好讲的,这题很恶心,卡常卡精度还爆int,要各种优化,有些dalao写的很复杂 ...

  5. commander.js

    参考链接: http://yijiebuyi.com/blog/2cd3833e8551a302b4ec645031bfd3d0.html http://blog.gejiawen.com/2016/ ...

  6. bzoj1095: [ZJOI2007]Hide 捉迷藏 线段树维护括号序列 点分治 链分治

    这题真是十分难写啊 不管是点分治还是括号序列都有一堆细节.. 点分治:时空复杂度$O(n\log^2n)$,常数巨大 主要就是3个堆的初始状态 C堆:每个节点一个,为子树中的点到它父亲的距离的堆. B ...

  7. 算法设计与分析第2章 递归与分治策略

    第2章 递归与分治策略 2.1 递归算法 递归算法:直接或间接地调用自身的算法. 递归函数:用函数自身给出定义的函数.两个要素:边界条件.递归方程 优点:结构清晰,可读性强,而且容易用数学归纳法来证明 ...

  8. 1164: 分治 逆序对

    1164: 分治 逆序对 时间限制: 1 Sec  内存限制: 128 MB 题目描述 给一列数a1,a2,...,an,求它的逆序对数,即有多少个有序对(i,j),使得i<j且ai>aj ...

  9. 递归/分治:归并排序

    前言 分治算法: 将一个规模为N的问题分解为K个规模较小的子问题,这些子问题相互独立且与原问题性质相同.求出 子问题的解后进行合并,就可得到原问题的解. 步骤如下: 分解,将要解决的问题划分成若 干规 ...

最新文章

  1. 23设计模式简介笔记
  2. 6,bash入门,for 循环, 编写最简单的脚本
  3. 深度学习NCHW和NHWC数据格式(由三维数据转换成一维数据的遍历方式)
  4. java怎么获取城市气温_获取城市天气数据
  5. 谈谈实习期间应该注意的几点问题,助你早日拿到转正offer
  6. BugkuCTF-WEB题login1
  7. 洛谷3396 哈希冲突 【分块】
  8. 《跟李沐读论文》之对比学习
  9. 大学生生涯规划1000字计算机专业,计算机大学生职业生涯规划书1000字
  10. com.sun.jna.Pointer类的方法
  11. java 隐藏父类方法,java 子类继承父类成员变量的隐藏、实现方法的重写
  12. matlab低频滤波编程,各位朋友:求教用c语言实现低通滤波的程序!!!
  13. 关于对齐次裁剪空间及HLSL语义的理解
  14. 几行Python代码实现自动陪女友聊天,制作开心机器人
  15. 从哪里租vps远程桌面服务器,vps远程桌面服务器出租
  16. 【蓝桥杯每日一练:跳蛙】
  17. android调用在线天气服务,android通过google api获取天气信息示例
  18. 【十个】工资是职场最大的陷阱,可怕的是很多人还不知道……
  19. Ubuntu20.04主题美化
  20. 超表面学习 初步印象

热门文章

  1. Android开发之View双指缩放ViewGroup双指缩放视频双指缩放图片双指缩放
  2. 使用百度API进行关键点识别
  3. vue.js分页组件(新手学习记录)
  4. Docker 安装创建
  5. Cisco 2811 IOS 升级实战
  6. SCCM 2012系列3 安装SCCM 2012
  7. 关于迪杰斯特拉算法(最短路)的PHP实现
  8. json类的解析,调试实例
  9. iframe嵌套改变url地址
  10. H5添加QQ好友的链接