-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path71270644.cpp
More file actions
54 lines (53 loc) · 894 Bytes
/
71270644.cpp
File metadata and controls
54 lines (53 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200*1000+100;
vector<int>adj[N];
int color[N];
int k;
void dfs(int x,int e){
int cur=1;
for(auto u:adj[x]){
if(u==e)continue;
if(cur==color[x])
cur++;
if(cur==color[e])
cur++;
if(cur==color[x])
cur++;
color[u]=cur;
cur++;
dfs(u,x);
}
}
void test(){
int m;
cin>>m;
int leaf=-1;
int n=m;
while(--n){
int a,b;
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i=1;i<=m;i++)
if(adj[i].size()==1) leaf=i;
int k=1;
for(int i=1;i<=m;i++)
k=max(k,(int)adj[i].size()+1);
color[leaf]=1;
dfs(leaf,0);
cout<<k<<endl;
for(int i=1;i<=m;i++)
cout<<color[i]<<" ";
cout<<endl;
}
int main()
{
int t=1;
// cin>>t;
while(t--){
test();
}
}