Codeforces 321C Ciel the Commander

Source: Internet
Author: User

Ciel the Commandertime limit:1000msmemory limit:262144kbthis problem would be judged onCodeforces. Original id:321c
64-bit integer IO format: %i64d Java class name: (any) Now Fox Ciel becomes a commander of the Tree land. Tree land, like its name said, have N cities connected by N -1 undirected roads, and for any of the cities there always exists a path Between them.

Fox Ciel needs to assign a officer to each city. Each officer have a rank-a letter from 'a ' to 'Z '. So there would be different ranks, and 'A ' are the topmost, so ' Z ' is thebottommost.

There is enough officers of each rank. But there was a special rule must obey:if x and y are both distinct cities and their officers hav E the same rank, then on the simple path between xand y There must is a city z that have an officer with higher rank. The rule guarantee that a communications between same rank officers would 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 a integer n (2≤ n ≤105)-the number of cities in Tree land.

Each of the following n -1 lines contains double integers a and b (1≤ a, bn, ab)-they mean that there'll be is an undirected road BETW Een a and b. Consider all the cities is numbered from 1 to n.

It guaranteed that the given graph would 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!".

Sample InputInput
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
Hint

In the first example, for any and officers of rank 'B ', an officer with rank ' A ' would be on thepath between them. So it's a valid solution.

SourceCodeforces Round #190 (Div. 1) Solve the problem: the depth of tree division is greater than 26, indicating impossible
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =100010;4 BOOLDONE[MAXN];5vector<int>G[MAXN];6 CharANS[MAXN];7 intSZ[MAXN],MAXSON[MAXN];8 intDfsintUintFA) {9Sz[u] =1;TenMaxson[u] =0; One      for(inti = g[u].size ()-1; I >=0; --i) { A         if(G[u][i] = = FA | | done[g[u][i]])Continue; - DFS (g[u][i],u); -Sz[u] + =Sz[g[u][i]]; theMaxson[u] =Max (Maxson[u],sz[g[u][i]]); -     } -     returnSz[u]; - } + intFindRoot (Const intSumintUintFA) { -     intRET =u; +Maxson[u] = max (Maxson[u],sum-Sz[u]); A      for(inti = g[u].size ()-1; I >=0; --i) { at         if(G[u][i] = = FA | | done[g[u][i]])Continue; -         intx =FindRoot (sum,g[u][i],u); -         if(Maxson[x] < Maxson[ret]) ret =x; -     } -     returnret; - } in BOOLSolveintUCharch) { -     introot = FindRoot (Dfs (U,0), U,0); toDone[root] =true; +Ans[root] =ch; -     if(Ch >'Z')return false; the      for(inti = g[root].size ()-1; I >=0; --i) { *         if(Done[g[root][i]])Continue; $         if(!solve (G[root][i],ch +1))return false;Panax Notoginseng     } -     return true; the } + intMain () { A     intn,u,v; the      while(~SCANF ("%d",&N)) { +          for(inti =0; I <= N; ++i) { -Done[i] =false; $ g[i].clear (); $         } -          for(inti =1; I < n; ++i) { -scanf"%d%d",&u,&v); the G[u].push_back (v); - g[v].push_back (u);Wuyi         } the         if(Solve (1,'A')) -          for(inti =1; I <= N; ++i) Wuprintf"%c%c", ans[i],i = = n?'\ n':' '); -         ElsePuts"impossible!"); About     } $     return 0; -}
View Code

Codeforces 321C Ciel the Commander

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.