日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Codeforce 322E Ciel the Commander (点分治)

發(fā)布時(shí)間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforce 322E Ciel the Commander (点分治) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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.

這個(gè)題,我真的不知道什么是點(diǎn)分治。

我們就題論題,這個(gè)題說(shuō)要是點(diǎn)分治我不太懂,但是這個(gè)題我的思路很簡(jiǎn)單。這個(gè)題題意是說(shuō)給一棵樹(shù),子節(jié)點(diǎn)的級(jí)別相同的時(shí)父節(jié)點(diǎn)的級(jí)別一定是高于他們的。開(kāi)始是這么理解的,但是后來(lái)我發(fā)現(xiàn)不是這么回事,放兩張圖大家理解一下。就明白為什么每次都需要找重心了。

一開(kāi)始我想的是這樣:

?

但是后來(lái)我發(fā)現(xiàn)如果是這種情況的話:

?

?

?

?只有這樣才能把節(jié)點(diǎn)使用的最少進(jìn)而達(dá)到題目要求。

#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; }//找樹(shù)的重心 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; }

?

總結(jié)

以上是生活随笔為你收集整理的Codeforce 322E Ciel the Commander (点分治)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。