#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200002];
bool visited[200002];
int colors[200002];
int parent_colors[200002];
queue<int> dis_colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }

    }

    queue<int> cmn;
    for (int i = 1; i <= max_color; i++)
        cmn.push(i);
    for (int i = 1; i <= n; i++)
        dis_colors[i] = cmn;

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    dis_colors[1].pop();
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = dis_colors[1].front();
        dis_colors[1].pop();
        parent_colors[v[max_degree_node][i]] = 1;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++){
        if (visited[v[max_degree_node][i]] == false])
            bfs(v[max_degree_node][i]);
    }

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d\n", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                int z;
                while (!dis_colors[y].empty()){
                    z = dis_colors[y].front();
                    dis_colors[y].pop();
                    if (z != parent_colors[y] && z != colors[y]){
                        colors[v[y][i]] = z;
                        parent_colors[v[y][i]] = colors[y];
                        break;
                    } else
                        dis_colors[y].push(z);
                }

            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int colors[200002];
int parent_colors[200002];
queue<int> dis_colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }

    }

    queue<int> cmn;
    for (int i = 1; i <= max_color; i++)
        cmn.push(i);
    for (int i = 1; i <= n; i++)
        dis_colors[i] = cmn;

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    dis_colors[1].pop();
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = dis_colors[1].front();
        dis_colors[1].pop();
        parent_colors[v[max_degree_node][i]] = 1;
        visited[v[max_degree_node][i]] = true;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++)
        bfs(v[max_degree_node][i]);

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d\n", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                int z;
                while (!dis_colors[y].empty()){
                    z = dis_colors[y].front();
                    dis_colors[y].pop();
                    if (z != parent_colors[y] && z != colors[y]){
                        colors[v[y][i]] = z;
                        parent_colors[v[y][i]] = colors[y];
                        break;
                    } else
                        dis_colors[y].push(z);
                }

            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200002];
bool visited[200002];
int colors[200002];
int parent_colors[200002];
queue<int> dis_colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }

    }

    queue<int> cmn;
    for (int i = 1; i <= max_color; i++)
        cmn.push(i);
    for (int i = 1; i <= n; i++)
        dis_colors[i] = cmn;

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    dis_colors[1].pop();
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = dis_colors[1].front();
        dis_colors[1].pop();
        parent_colors[v[max_degree_node][i]] = 1;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++){
        if (visited[v[max_degree_node][i]] == false)
            bfs(v[max_degree_node][i]);
    }

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d\n", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                int z;
                while (!dis_colors[y].empty()){
                    z = dis_colors[y].front();
                    dis_colors[y].pop();
                    if (z != parent_colors[y] && z != colors[y]){
                        colors[v[y][i]] = z;
                        parent_colors[v[y][i]] = colors[y];
                        break;
                    } else
                        dis_colors[y].push(z);
                }

            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int visited_neighbours[200001];
int colors[200002];
int parent_colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }

    }

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = i + 2;
        parent_colors[v[max_degree_node][i]] = 1;
        visited[v[max_degree_node][i]] = true;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++)
        bfs(v[max_degree_node][i]);

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d ", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                for (int j = 1; j <= max_color; j++){
                    if (j != parent_colors[y] && j!= colors[y]){
                        colors[v[y][i]] = j;
                        parent_colors[v[y][i]] = colors[y];
                        break;
                    }
                }
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int colors[200002];
int parent_colors[200002];
queue<int> dis_colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }

    }

    queue<int> cmn;
    for (int i = 1; i <= max_color; i++)
        cmn.push(i);
    for (int i = 1; i <= n; i++)
        dis_colors[i] = cmn;

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    dis_colors[1].pop();
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = dis_colors[1].front();
        dis_colors[1].pop();
        parent_colors[v[max_degree_node][i]] = 1;
        visited[v[max_degree_node][i]] = true;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++)
        bfs(v[max_degree_node][i]);

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d ", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                int z;
                while (!dis_colors[y].empty()){
                    z = dis_colors[y].front();
                    dis_colors[y].pop();
                    if (z != parent_colors[y] && z != colors[y]){
                        colors[v[y][i]] = z;
                        parent_colors[v[y][i]] = colors[y];
                        break;
                    }
                }

            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int colors[200002];
int parent_colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }

    }

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = i + 2;
        parent_colors[v[max_degree_node][i]] = 1;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++){
        if (visited[v[max_degree_node][i]] == false)
            bfs(v[max_degree_node][i]);
    }

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d ", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                for (int j = 1; j <= max_color; j++){
                    if (j != colors[y] && j != parent_colors[y]){
                        colors[v[y][i]] = j;
                        parent_colors[v[y][i]] = colors[y];
                    }
                }
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int visited_neighbours[200001];
int colors[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        max_color = max(max_color, current_degree + 1);
    }
    bfs(1);

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d ", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    colors[x] = 1;
    int counter = 1;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                counter++;
                if ((counter %  (max_color + 1)) == colors[y] || counter % (max_color + 1) == 0)
                    counter++;
                colors[v[y][i]] = counter % (max_color + 1);
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int visited_neighbours[200001];
int colors[200002];
int parent_colors[200002];
int left_bound[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }
        left_bound[i] = 1;
    }

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = i + 2;
        parent_colors[v[max_degree_node][i]] = 1;
        visited[v[max_degree_node][i]] = true;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++)
        bfs(v[max_degree_node][i]);

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d ", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){

            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                while(left_bound[y] <= max_color){
                    if (left_bound[y] != parent_colors[y] && left_bound[y] != colors[y]){
                        colors[v[y][i]] = left_bound[y];
                        parent_colors[v[y][i]] = colors[y];
                        break;
                    }
                    left_bound[y]++;
                }
                left_bound[y]++;
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

void bfs(int x);

int n;
int max_color = INT_MIN;
vector<int> v[200001];
bool visited[200001];
int colors[200002];
int parent_colors[200002];
int left_bound[200002];

int main()
{
    scanf("%d", &n);
    int a, b;
    for (int i = 1; i < n; i++){
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    /* ------------------- */

    int max_degree_node;
    for (int i = 1; i <= n; i++){
        int current_degree = v[i].size();
        if (current_degree + 1 > max_color){
            max_color = current_degree + 1;
            max_degree_node = i;
        }
        left_bound[i] = 1;
    }

    colors[max_degree_node] = 1;
    visited[max_degree_node] = true;
    for (int i = 0; i < v[max_degree_node].size(); i++){
        colors[v[max_degree_node][i]] = i + 2;
        parent_colors[v[max_degree_node][i]] = 1;
        visited[v[max_degree_node][i]] = true;
    }

    for (int i = 0; i < v[max_degree_node].size(); i++)
        bfs(v[max_degree_node][i]);

    printf("%d\n", max_color);
    for (int i = 1; i <= n; i++)
        printf("%d ", colors[i]);

    return 0;
}

void bfs(int x){
    visited[x] = true;
    queue<int> q;
    q.push(x);

    int y;
    while (!q.empty()){
        y = q.front();
        q.pop();

        for (int i = 0; i < v[y].size(); i++){
            if (visited[v[y][i]] == false){
                visited[v[y][i]] = true;
                q.push(v[y][i]);
                while(left_bound[y] <= max_color  && colors[v[y][i]] != 0){
                    if (left_bound[y] != parent_colors[y] && left_bound[y] != colors[y]){
                        colors[v[y][i]] = left_bound[y];
                        parent_colors[v[y][i]] = colors[y];
                    }
                    left_bound[y]++;
                }
                left_bound[y]++;
            }
        }
    }
}


#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
vector<int> v[100005];
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,i,k=0;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	v[x].pb(y);
    	v[y].pb(x);
    }
    for(i=1;i<=n;i++)
    {
    	int ha = v[i].size();
    	k = max(k,ha);
    }
    k++;
    bool vi[100005] = {false};
    int ans[100005];
    int par[100005];
    memset(par,-1,sizeof(par));
    vi[1] = true;
    stack<int> s;
    s.push(1);
    ans[1] = 1;
    while(!s.empty())
    {
    	int st = s.top();
    	s.pop();
    	for(auto u: v[st])
    	{
    		if(!vi[u])
    		{
    			vi[u] = true;
    			par[u] = st;
    			s.push(u);
    			if(par[st]!=-1)
    			{
    				for(i=1;i<=k;i++)
    				{
    					if(i!=ans[st] && i!=ans[par[st]])
    					{
    						ans[u] = i;
    						break;
    					}
    				}
    			}
    			else
    			{
    				ans[u] = ans[st] + 1;
    			}
    		}
    	}
    }
    cout<<k<<"\n";
    for(i=1;i<=n;i++) cout<<ans[i]<<" ";

}


#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
vector<int> v[200005];
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,i,k=0;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	v[x].pb(y);
    	v[y].pb(x);
    }
    for(i=1;i<=n;i++)
    {
    	int ha = v[i].size();
    	k = max(k,ha);
    }
    k++;
    bool vi[200005] = {false};
    int ans[200005];
    int par[200005];
    memset(par,-1,sizeof(par));
    vi[1] = true;
    stack<int> s;
    s.push(1);
    ans[1] = 1;
    int num=2;
    while(!s.empty())
    {
    	int st = s.top();
    	s.pop();
    	int nu=1;
    	for(auto u: v[st])
    	{
    		if(!vi[u])
    		{
    			vi[u] = true;
    			par[u] = st;
    			s.push(u);
    			if(par[st]==-1)
    			{
    				ans[u] = num;
    				num++;
    			}
    			else
    			{
    				for(i=nu;i<=n;i++)
    				{
    					if(i!=ans[st] && i!=ans[par[st]])
    					{
    						ans[u] = i;
    						break;
    					}
    				}
    				nu = i+1;
    			}
    		}
    	}
    }
    cout<<k<<"\n";
    for(i=1;i<=n;i++) cout<<ans[i]<<" ";

}


#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
vector<int> v[100005];
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,i,k=0;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	v[x].pb(y);
    	v[y].pb(x);
    }
    for(i=1;i<=n;i++)
    {
    	int ha = v[i].size();
    	k = max(k,ha);
    }
    k++;
    bool vi[100005] = {false};
    int ans[100005];
    int par[100005];
    memset(par,-1,sizeof(par));
    vi[1] = true;
    stack<int> s;
    s.push(1);
    ans[1] = 1;
    int num=2;
    while(!s.empty())
    {
    	int st = s.top();
    	s.pop();
    	int nu=1;
    	for(auto u: v[st])
    	{
    		if(!vi[u])
    		{
    			vi[u] = true;
    			par[u] = st;
    			s.push(u);
    			if(par[st]==-1)
    			{
    				ans[u] = num;
    				num++;
    			}
    			else
    			{
    				for(i=nu;i<=n;i++)
    				{
    					if(i!=ans[st] && i!=ans[par[st]])
    					{
    						ans[u] = i;
    						break;
    					}
    				}
    				nu = i+1;
    			}
    		}
    	}
    }
    cout<<k<<"\n";
    for(i=1;i<=n;i++) cout<<ans[i]<<" ";

}


#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
vector<int> v[100005];
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,i,k=0;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
    	int x,y;
    	cin>>x>>y;
    	v[x].pb(y);
    	v[y].pb(x);
    }
    for(i=1;i<=n;i++)
    {
    	int ha = v[i].size();
    	k = max(k,ha);
    }
    k++;
    bool vi[100005] = {false};
    int ans[100005];
    vi[1] = true;
    stack<int> s;
    s.push(1);
    ans[1] = 1;
    int num = 2;
    while(!s.empty())
    {
    	int st = s.top();
    	s.pop();
    	for(auto u: v[st])
    	{
    		if(!vi[u])
    		{
    			vi[u] = true;
    			s.push(u);
    			int ta;
    			if(num%k==0) ta = k,num = 1;
    			else ta = num%k,num++;
    			ans[u] = ta;
    		}
    	}
    }
    cout<<k<<"\n";
    for(i=1;i<=n;i++) cout<<ans[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pii> >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=2e5+2;
const int inf= (int)(1e19+10LL);
Vl graph[sze];
int mxcolor=0;
bool visited[sze];
int color[sze];
void dfs(int src,int parent,int clr){
  	visited[src]=true;
  	bool used[sze];
  	for(auto it:graph[src]){
		if(visited[it])continue;

		for(int i=1;i<=mxcolor;i++){
			  if(i!=clr && (i!=color[parent]) && !used[i]){
				  used[i]=true;
				  color[it]=i;
				  break;
			  }

		}
		dfs(it,src,color[it]);

	}

}

void solve()
{
  int n;
  sl(n);
  for(int i=1;i<=n-1;i++){
	  int u,v;
	  sl(u);sl(v);
	  graph[u].pb(v);
	  graph[v].pb(u);
	  mxcolor=max(mxcolor,(int)graph[u].size());
	  mxcolor=max(mxcolor,(int)graph[v].size());
  }
  mxcolor++;
  ms(color,-1);
  ms(visited,false);
  color[1]=1;
  dfs(1,-1,1);
  set<int>st;
  for(int i=1;i<=n;i++)st.insert(color[i]);
  cout<<st.size()<<endl;
  for(int i=1;i<=n;i++)cout<<color[i]<<" ";

}

signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();

   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pii> >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=2e5+2;
const int inf= (int)(1e19+10LL);
Vl graph[sze];
int mxcolor=0;
bool visited[sze];
int color[sze];
void dfs(int src,int parent,int clr){
  	visited[src]=true;
  	bool used[sze];
  	for(auto it:graph[src]){
		if(visited[it])continue;

		for(int i=1;i<=mxcolor;i++){
			if(parent>-1){
				if(i!=clr && (i!=color[parent]) && !used[i]){
				  used[i]=true;
				  color[it]=i;
				  break;
			  }

			}
			else{
			  if(i!=clr && !used[i]){
				  used[i]=true;
				  color[it]=i;
				  break;
			  }
		  }

		}
		dfs(it,src,color[it]);

	}

}

void solve()
{
  int n;
  sl(n);
  for(int i=1;i<=n-1;i++){
	  int u,v;
	  sl(u);sl(v);
	  graph[u].pb(v);
	  graph[v].pb(u);
	  mxcolor=max(mxcolor,(int)graph[u].size());
	  mxcolor=max(mxcolor,(int)graph[v].size());
  }
  mxcolor++;
  ms(color,-1);
  ms(visited,false);
  color[1]=1;
  dfs(1,-1,1);
  set<int>st;
  for(int i=1;i<=n;i++)st.insert(color[i]);
  cout<<st.size()<<endl;
  for(int i=1;i<=n;i++)cout<<color[i]<<" ";

}

signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();

   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pii> >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=2e5+2;
const int inf= (int)(1e19+10LL);
Vl graph[sze];
int mxcolor=0;
bool visited[sze];
int color[sze];
void dfs(int src,int parent,int clr){
  	visited[src]=true;
  	int i=1;
  	for(auto it:graph[src]){
		if(visited[it])continue;
		for(;i<=mxcolor;i++){
			if(color[src]!=i && color[parent]!=i){
				  color[it]=i;
				  i++;
				  break;
			  }

			}
		dfs(it,src,color[it]);
	   }
	}
void solve()
{
  int n;
  sl(n);
  for(int i=1;i<=n-1;i++){
	  int u,v;
	  sl(u);sl(v);
	  graph[u].pb(v);
	  graph[v].pb(u);
	  mxcolor=max(mxcolor,(int)graph[u].size());
	  mxcolor=max(mxcolor,(int)graph[v].size());
  }
  mxcolor++;
  ms(color,-1);
  ms(visited,false);
  color[1]=1;
  dfs(1,0,1);
  set<int>st;
  for(int i=1;i<=n;i++)st.insert(color[i]);
  cout<<st.size()<<endl;
  for(int i=1;i<=n;i++)cout<<color[i]<<" ";

}

signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();

   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pii> >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=1e5+2;
const int inf= (int)(1e19+10LL);
Vl graph[sze];
int mxcolor=0;
bool visited[sze];
int color[sze];
void dfs(int src,int parent,int clr){
  	visited[src]=true;
  	bool used[sze];
  	for(auto it:graph[src]){
		if(visited[it])continue;

		for(int i=1;i<=mxcolor;i++){
			  if(i!=clr && (i!=color[parent]) && !used[i]){
				  used[i]=true;
				  color[it]=i;
				  break;
			  }

		}
		dfs(it,src,color[it]);

	}

}

void solve()
{
  int n;
  sl(n);
  for(int i=1;i<=n-1;i++){
	  int u,v;
	  sl(u);sl(v);
	  graph[u].pb(v);
	  graph[v].pb(u);
	  mxcolor=max(mxcolor,(int)graph[u].size());
	  mxcolor=max(mxcolor,(int)graph[v].size());
  }
  mxcolor++;
  ms(color,-1);
  ms(visited,false);
  color[1]=1;
  dfs(1,-1,1);
  set<int>st;
  for(int i=1;i<=n;i++)st.insert(color[i]);
  cout<<st.size()<<endl;
  for(int i=1;i<=n;i++)cout<<color[i]<<" ";

}

signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();

   }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,color[200001],pre[200001],MAX;
vector<int>e[200001];
bool used[200001],Lock[200001];
deque<int>dq;
void BFS(int u){
    used[u]=true;
    color[u]=1;
    dq.push_back(u);
    while(!dq.empty()){
        int u=dq.front();
        dq.pop_front();
        int curr=color[u];
        if(pre[pre[u]]!=0){
            Lock[color[pre[pre[u]]]]=false;
            curr=color[pre[pre[u]]]-1;
        }
        Lock[color[u]]=true;
        Lock[color[pre[u]]]=true;
        for(int i=0;i<e[u].size();i++){
            int v=e[u][i];
            if(!used[v]){
                pre[v]=u;
                color[v]=++curr;
                MAX=max(MAX,color[v]);
                Lock[color[v]]=true;
                used[v]=true;
                dq.push_back(v);
            }
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    BFS(1);
    cout<<MAX<<"\n";
    for(int i=1;i<=n;i++) cout<<color[i]<<" ";;
}


#include<bits/stdc++.h>
using namespace std;
int n,color[200001],pre[200001],MAX;
vector<int>e[200001];
bool used[200001],Lock[200001];
deque<int>dq;
void BFS(int u){
    used[u]=true;
    color[u]=1;
    dq.push_back(u);
    while(!dq.empty()){
        int u=dq.front();
        dq.pop_front();
        int curr=color[u];
        if(pre[pre[u]]!=0){
            Lock[color[pre[pre[u]]]]=false;
            curr=color[pre[pre[u]]]-1;
        }
        Lock[color[u]]=true;
        Lock[color[pre[u]]]=true;
        for(int i=0;i<e[u].size();i++){
            int v=e[u][i];
            if(!used[v]){
                pre[v]=u;
                color[v]=++curr;
                MAX=max(MAX,color[v]);
                Lock[color[v]]=true;
                used[v]=true;
                dq.push_back(v);
            }
        }
    }
}
main(){
    //freopen("Color.inp","r",stdin);
    //freopen("Color.out","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        if(e[i].size()==1){
            u=i;
            break;
        }
    }
    BFS(u);
    cout<<MAX<<"\n";
    for(int i=1;i<=n;i++) cout<<color[i]<<" ";;
}


#include<bits/stdc++.h>
using namespace std;
int n,color[200001],pre[200001],MAX;
vector<int>e[200001];
bool used[200001],lock[200001];
deque<int>dq;
void BFS(int u){
    used[u]=true;
    color[u]=1;
    dq.push_back(u);
    while(!dq.empty()){
        int u=dq.front();
        dq.pop_front();
        int curr=color[u];
        if(pre[pre[u]]!=0){
            lock[color[pre[pre[u]]]]=false;
            curr=color[pre[pre[u]]]-1;
        }
        lock[color[u]]=true;
        lock[color[pre[u]]]=true;
        for(int i=0;i<e[u].size();i++){
            int v=e[u][i];
            if(!used[v]){
                pre[v]=u;
                color[v]=++curr;
                MAX=max(MAX,color[v]);
                lock[color[v]]=true;
                used[v]=true;
                dq.push_back(v);
            }
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    BFS(1);
    cout<<MAX<<"\n";
    for(int i=1;i<=n;i++) cout<<color[i]<<" ";;
}


#include<bits/stdc++.h>
using namespace std;
int n,color[200001],pre[200001],MAX,lock[200001];
vector<int>e[200001];
bool used[200001];
deque<int>dq;
void BFS(int u){
    used[u]=true;
    color[u]=1;
    dq.push_back(u);
    while(!dq.empty()){
        int u=dq.front();
        dq.pop_front();
        int curr=color[u];
        if(pre[pre[u]]!=0){
            lock[color[pre[pre[u]]]]=1;
            curr=color[pre[pre[u]]]-1;
        }
        lock[color[u]]=1;
        lock[color[pre[u]]]=1;
        for(int i=0;i<e[u].size();i++){
            int v=e[u][i];
            if(!used[v]){
                pre[v]=u;
                color[v]=++curr;
                MAX=max(MAX,color[v]);
                lock[color[v]]=1;
                used[v]=true;
                dq.push_back(v);
            }
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    BFS(1);
    cout<<MAX<<"\n";
    for(int i=1;i<=n;i++) cout<<color[i]<<" ";;
}


#include<bits/stdc++.h>
using namespace std;
int n,colour[200001],MAX,p[200001];
vector<int>e[200001];
bool used[200001];
void DFS(int u){
    used[u]=true;
    int pre=1;
    for(auto v : e[u]){
        if(used[v]) continue;
        p[v]=u;
        while(pre==colour[u] || pre==colour[p[u]]) pre++;
        colour[v]=pre;
        MAX=max(MAX,pre++);
        DFS(v);
    }
}
main(){
    //freopen("Color.inp","r",stdin);
    //freopen("Color.out","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    int u,v;
    for(int i=1;i<n;i++){
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    colour[1]=1;
    DFS(1);
    cout<<MAX<<"\n";
    for(int i=1;i<=n;i++) cout<<colour[i]<<" ";
}


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[100001];
bool vis[100001];
int col[100001];

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      int v,maxdeg=0;

      for(int i=1;i<=n;i++){
        if(gr[i].size()>maxdeg){
          maxdeg=gr[i].size();
          v=i;
        }
      }
      memset(col,0,sizeof(col));
      col[v]=1;
      int k=2;
      for(auto it:gr[v])
      {
        col[it]=k++;
      }
      k=maxdeg+1;
      for(int i=1;i<=n;i++){
        if(col[i]==0){
          unordered_set<int> used;
          for(auto it:gr[i]){
              if(col[it]!=0)
              used.insert(col[it]);
              for(auto v:gr[it]){
                if(v!=it)
                {
                  if(col[v]!=0)
                  used.insert(col[v]);
                }

            }
          }
          for(int j=1;j<=k;j++){
            if(used.find(j)==used.end())
            {
              col[i]=j;
              break;
            }
          }
        }
      }
      cout<<k<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[200001];
bool vis[200001];
int col[200001];

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      int v,maxdeg=0;

      for(int i=1;i<=n;i++){
        if(gr[i].size()>maxdeg){
          maxdeg=gr[i].size();
          v=i;
        }
      }
      memset(col,0,sizeof(col));
      col[v]=1;
      int k=2;

      for(auto it:gr[v])
      {
        col[it]=k++;
      }
      k=maxdeg+1;
      queue<int> q;
      q.push(v);

      while(!q.empty()){

      v=q.front();
      q.pop();

      for(auto it:gr[v]){
        if(it!=v)
        for(auto u:gr[it]){
          if(u!=it && col[u]==0){
            int c1=col[v];
            int c2=col[it];
            for(int j=1;j<=k;j++){
              if(j!=c1 && j!=c2)
              {
                col[u]=j;
                break;
              }
            }
            unordered_set<int> st;
            st.insert(col[u]);
            st.insert(col[it]);

            for(auto x:gr[u]){
              if(x!=u && col[x]==0){
                for(int j=1;j<=k;j++){
                  if(st.find(j)==st.end()){
                    st.insert(j);
                    col[x]=j;
                    break;
                  }
                }
              }
            }
            q.push(u);
          }
        }
      }
    }
      cout<<k<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[200001];
bool vis[200001];
int col[200001];

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      int v,maxdeg=0;

      for(int i=1;i<=n;i++){
        if(gr[i].size()>maxdeg){
          maxdeg=gr[i].size();
          v=i;
        }
      }
      memset(col,0,sizeof(col));
      col[v]=1;
      int k=2;

      for(auto it:gr[v])
      {
        col[it]=k++;
      }
      k=maxdeg+1;
      queue<int> q;
      q.push(v);

      while(!q.empty()){

      v=q.front();
      q.pop();

      for(auto it:gr[v]){
        for(auto u:gr[it]){
          if(u!=it && col[u]==0){
            int c1=col[v];
            int c2=col[it];
            for(int j=1;j<=k;j++){
              if(j!=c1 && j!=c2)
              {
                col[u]=j;
                break;
              }
            }
            unordered_set<int> st;
            st.insert(col[u]);
            st.insert(col[it]);

            for(auto x:gr[u]){
              if(x!=u && col[x]==0){
                for(int j=1;j<=k;j++){
                  if(st.find(j)==st.end()){
                    st.insert(j);
                    col[x]=j;
                    break;
                  }
                }
              }
            }
            q.push(u);
          }
        }
      }
    }
      cout<<k<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[200001];
//bool vis[200001];
int col[200001];
int ans;

void dfs(int v,int p){
  int cur=1;
  for(auto it:gr[v]){
    if(it==p)
    continue;

    while(cur==col[p]||cur==col[v])
    cur++;

    col[it]=cur++;
    ans=max(ans,col[it]);
    dfs(it,v);
  }
}

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      forn(i,1,n+1)
      col[i]=-1;

      col[1]=1;
      ans=0;
      dfs(1,0);

      cout<<ans<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[200001];
//bool vis[200001];
int col[200001];
int ans;

void dfs(int v,int p){
  int cur=1;
  for(auto it:gr[v]){
    if(it==p)
    continue;

    while(cur==col[p]||cur==col[v])
    cur++;

    col[it]=cur;
    ans=max(ans,cur);
    dfs(it,v);
  }
}

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      forn(i,1,n+1)
      col[i]=-1;

      col[1]=1;
      ans=0;
      dfs(1,0);

      cout<<ans<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[200001];
bool vis[200001];
int col[200001];

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      int v,maxdeg=0;

      for(int i=1;i<=n;i++){
        if(gr[i].size()>maxdeg){
          maxdeg=gr[i].size();
          v=i;
        }
      }
      memset(col,0,sizeof(col));
      col[v]=1;
      int k=2;
      for(auto it:gr[v])
      {
        col[it]=k++;
      }
      k=maxdeg+1;
      for(int i=1;i<=n;i++){
        if(col[i]==0){
          unordered_set<int> used;
          for(auto it:gr[i]){
              if(col[it]!=0)
              used.insert(col[it]);
              for(auto v:gr[it]){
                if(v!=it)
                {
                  if(col[v]!=0)
                  used.insert(col[v]);
                }

            }
          }
          for(int j=1;j<=k;j++){
            if(used.find(j)==used.end())
            {
              col[i]=j;
              break;
            }
          }
        }
      }
      cout<<k<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res)%hell;
    x=(x*x)%hell;
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

/*class CompareDist
{
public:
    bool operator()(pair<ll,int> a,pair<ll,int> b) {
        if(a.F!=b.F)
        return a.F<b.F;
        else
        return a.S>b.S;
    }
};*/

bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.S!=b.S)
  return (a.S<b.S);
  else
  return a.F<b.F;
}
vi gr[200001];
bool vis[200001];
int col[200001];
void dfs(int v,int p, int k){
  unordered_set<int> st;
  for(auto it:gr[p]){
    if(col[it]!=0)
    st.insert(col[it]);
  }
  st.insert(col[p]);
  for(int i=1;i<=k;i++){
    if(st.find(i)==st.end()){
      col[v]=i;
      break;
    }
  }
  for(auto it:gr[v]){
    if(it!=p)
    dfs(it,v,k);
  }
}

void solve(){

  int test;
  //cin>>test;
  test=1;
  while(test--){
      int n;
      cin>>n;

      forn(i,1,n){
        int a,b;
        cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
      }
      int v,maxdeg=0;

      for(int i=1;i<=n;i++){
        if(gr[i].size()>maxdeg){
          maxdeg=gr[i].size();
          v=i;
        }
      }
      memset(col,0,sizeof(col));
      col[v]=1;
      int k=maxdeg+1;
      for(auto it:gr[v]){
        dfs(it,v,k);
      }

      cout<<k<<'\n';
      for(int i=1;i<=n;i++)
      cout<<col[i]<<' ';
  }
}

/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}

ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
vector<int> adj[nax];
int color[nax];
bool vis[nax];
int n,u,v,mx,start;
void dfs(int node,int c)
 {
  vis[node] = 1;
  color[node] = c+1;
  for(int x : adj[node])
    if(!vis[x])
       {
         (c+=1)%=mx;
         dfs(x,c);
       }
 }
void solve()
 {
  cin>>n;
  mx = -1;
  loop(i,0,n-1)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
  loop(i,1,n+1)
  {
   if(adj[i].size() == 1)
     start = i;
   if(mx<(int)adj[i].size())
     {
      mx = (int)adj[i].size();
      start = i;
     }
  }
  mx++;
  dfs(start,1ll);
  loop(i,1,n+1)
   cout<<color[i]<<" ";
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
vector<int> adj[nax];
int color[nax];
int n,u,v,mx,start;
void dfs(int node,int p)
 {
  int c = 0;
  for(auto x : adj[node])
     if(!color[x])
        {
          while(c+1==p || c+1==color[node])
             (c+=1)%=mx;
          color[x] = c+1;
          (c+=1)%=mx;
          dfs(x,color[node]);
        }
 }

void solve()
 {
  cin>>n;
  mx = -1;
  loop(i,0,n-1)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
  loop(i,1,n+1)
   if(mx<(int)adj[i].size())
     {
      mx = (int)adj[i].size();
      start = i;
     }
  mx++;
  color[start] = 1;
  int c = 2;
  for(int x : adj[start])
    {
      color[x] = c;
      for(int y : adj[x])
        if(!color[y])
         dfs(y,color[x]);
      (c%=mx)+=1;
    }
  cout<<mx<<END;
  loop(i,1,n+1)
   cout<<color[i]<<" ";
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
vector<int> adj[nax];
int color[nax];
int n,u,v,mx,start;
void dfs(int node,int p)
 {
  int c = 1;
  for(auto x : adj[node])
     if(!color[x])
        {
          while(c==p || c==color[node])
             (c%=mx)+=1;
          color[x] = c;
          (c%=mx)+=1;
          dfs(x,color[node]);
        }
 }

void solve()
 {
  cin>>n;
  mx = -1;
  loop(i,0,n-1)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
  loop(i,1,n+1)
   if(mx<(int)adj[i].size())
     {
      mx = (int)adj[i].size();
      start = i;
     }
  mx++;
  color[start] = 1;
  int c = 2;
  for(int x : adj[start])
    {
      color[x] = c;
      for(int y : adj[x])
        if(!color[y])
         dfs(y,color[x]);
      (c%=mx)+=1;
    }
  cout<<mx<<END;
  loop(i,1,n+1)
   cout<<color[i]<<" ";
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
vector<int> adj[nax];
int color[nax];
int n,u,v,mx,start;
void dfs(int node,int p,int gp)
 {
  if(max(p,gp) == min(p,gp) + 1)
     {
      if(min(p,gp) == 1)
         color[node] = 3;
      else
         color[node] = min(p,gp) - 1;
     }
  else
     color[node] = (p+gp)/2;
  for(auto x : adj[node])
     if(!color[x])
        dfs(x,color[node],p);
 }

void solve()
 {
  cin>>n;
  mx = -1;
  loop(i,0,n-1)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
  loop(i,1,n+1)
   if(mx<(int)adj[i].size())
     {
      mx = (int)adj[i].size();
      start = i;
     }
  mx++;
  color[start] = 1;
  int c = 2;
  for(int x : adj[start])
    {
      color[x] = c;
      for(int y : adj[x])
        if(!color[y])
         dfs(y,color[x],1ll);
      (c%=mx)+=1;
    }
  cout<<mx<<END;
  loop(i,1,n+1)
   cout<<color[i]<<" ";
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
vector<int> adj[nax];
int color[nax];
int n,u,v,mx,start;
void dfs(int node,int p)
 {
  int c = 1;
  for(auto x : adj[node])
     if(!color[x])
        {
          while(c==p || c==color[node])
             (c%=mx)+=1;
          color[x] = c;
          (c%=mx)+=1;
          dfs(x,color[node]);
        }
 }

void solve()
 {
  cin>>n;
  mx = -1;
  loop(i,0,n-1)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
  loop(i,1,n+1)
   if(mx<(int)adj[i].size())
     {
      mx = (int)adj[i].size();
      start = i;
     }
  mx++;
  color[start] = 1;
  dfs(start,0ll);
  cout<<mx<<END;
  loop(i,1,n+1)
   cout<<color[i]<<" ";
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
vector<int> adj[nax];
int color[nax];
bool vis[nax];
int n,u,v,mx,start;
void dfs(int node,int c)
 {
  vis[node] = 1;
  color[node] = c+1;
  for(int x : adj[node])
    if(!vis[x])
       {
         (c+=1)%=mx;
         dfs(x,c);
       }
 }
void solve()
 {
  cin>>n;
  mx = -1;
  loop(i,0,n-1)
    {
      cin>>u>>v;
      adj[u].pb(v);
      adj[v].pb(u);
    }
  loop(i,1,n+1)
  {
   if(adj[i].size() == 1)
     start = i;
   if(mx<(int)adj[i].size())
     {
      mx = (int)adj[i].size();
      start = i;
     }
  }
  mx++;
  dfs(start,1ll);
  cout<<mx<<END;
  loop(i,1,n+1)
   cout<<color[i]<<" ";
 }
signed main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}


//https://www.hackerrank.com/challenges/equal/problem
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e5+10
int n;
vector<int> p[MAX];
int ncl;
vector<int> color(MAX, 0);
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int u, v;
    for(int i=1;i<n; i++){
        cin>>u>>v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    int root = 0;
    ncl = 0;
    for(int i=1; i<=n ;i++){
        u = p[i].size();
        if(u == 1) root = i;
        ncl = max(ncl, u);
    }
    ncl++;
    cout<<ncl<<endl;
    queue<int> q;
    q.push(root);
    vector<int> par(n+1, 0);
    color[root] = 1;
    par[root] = 0;
    while(!q.empty()){
        u = q.front();
        q.pop();
        v = color[u] ;
        for(auto y: p[u]){
            if(y == par[u]) continue;
            else{
                par[y] = u;
                while((v % ncl) + 1 == color[par[u]] || (v%ncl) + 1 == color[u]) v++;
                color[y] = v % ncl + 1;
                v++;
                q.push(y);
            }
        }
    }
    for(int i=1; i<=n; i++){
        cout<<color[i]<<' ';
    }
}


//https://www.hackerrank.com/challenges/equal/problem
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e5+10
int n;
vector<int> p[MAX];
int ncl;
void DFS(int x, int par, int k){
    cout<<(k % ncl) + 1<<' ';
    int i = 1;
    for(auto y: p[x]){
        if(y != par){
            DFS(y, x, k + i);
            i++;
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int u, v;
    for(int i=1;i<n; i++){
        cin>>u>>v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    ncl = 0;
    for(int i=1; i<=n ;i++){
        u = p[i].size();
        ncl = max(ncl, u);
    }
    ncl++;
    cout<<ncl<<endl;
    DFS(1, 0, 0);
}


//https://www.hackerrank.com/challenges/equal/problem
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)2e5+10
int n;
vector<int> p[MAX];
int ncl;
vector<int> color(MAX, 0);
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int u, v;
    for(int i=1;i<n; i++){
        cin>>u>>v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    int root = 0;
    ncl = 0;
    for(int i=1; i<=n ;i++){
        u = p[i].size();
        if(u == 1) root = i;
        ncl = max(ncl, u);
    }
    ncl++;
    cout<<ncl<<endl;
    queue<int> q;
    q.push(root);
    vector<int> par(n+1, 0);
    color[root] = 1;
    par[root] = 0;
    while(!q.empty()){
        u = q.front();
        q.pop();
        v = color[u] ;
        for(auto y: p[u]){
            if(y == par[u]) continue;
            else{
                par[y] = u;
                while((v % ncl) + 1 == color[par[u]] || (v%ncl) + 1 == color[u]) v++;
                color[y] = v % ncl + 1;
                v++;
                q.push(y);
            }
        }
    }
    for(int i=1; i<=n; i++){
        cout<<color[i]<<' ';
    }
}


//https://www.hackerrank.com/challenges/equal/problem
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e5+10
int n;
vector<int> p[MAX];
int ncl;
vector<int> color(MAX, 0);
void DFS(int x, int par, int k){
    color[x] = k%ncl + 1;
    int i = 1;
    for(auto y: p[x]){
        if(y != par){
            DFS(y, x, k + i);
            i++;
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int u, v;
    for(int i=1;i<n; i++){
        cin>>u>>v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    int root = 0;
    ncl = 0;
    for(int i=1; i<=n ;i++){
        u = p[i].size();
        if(u == 1) root = i;
        ncl = max(ncl, u);
    }
    ncl++;
    cout<<ncl<<endl;
    DFS(root, 0, 0);
    for(int i=1; i<=n; i++){
        cout<<color[i]<<' ';
    }
}


//https://www.hackerrank.com/challenges/equal/problem
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e5+10
int n;
vector<int> p[MAX];
int ncl;
vector<int> color(MAX, 0);
void DFS(int x, int par, int k){
    color[x] = k%ncl + 1;
    int i = 1;
    for(auto y: p[x]){
        if(y != par){
            DFS(y, x, k + i);
            i++;
        }
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int u, v;
    for(int i=1;i<n; i++){
        cin>>u>>v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    ncl = 0;
    for(int i=1; i<=n ;i++){
        u = p[i].size();
        ncl = max(ncl, u);
    }
    ncl++;
    cout<<ncl<<endl;
    DFS(1, 0, 0);
    for(int i=1; i<=n; i++){
        cout<<color[i]<<' ';
    }
}


//https://www.hackerrank.com/challenges/equal/problem
#include<bits/stdc++.h>
using namespace std;
#define MAX (int)1e5+10
int n;
vector<int> p[MAX];
int k, ncl;
void DFS(int x, int par){
    cout<<(k % ncl) + 1<<' ';
    k++;
    for(auto y: p[x]){
        if(y != par) DFS(y, x);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    int u, v;
    for(int i=1;i<n; i++){
        cin>>u>>v;
        p[u].push_back(v);
        p[v].push_back(u);
    }
    ncl = 0;
    for(int i=1; i<=n ;i++){
        u = p[i].size();
        ncl = max(ncl, u);
    }
    ncl++;
    cout<<ncl<<endl;
    DFS(1, 0);
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define rep(i,a,b)  for( i=a;i<=b;i++)
#define re(i,a,b)  for( i=a;i>=b;i--)
#define pie  2 * acos(0.0)
using namespace std;
void solve();
void dfs(int ,int);
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
 //cin >> T;
 while(T--)
 {solve();
}
}
int c[100001];
bool vis[100001]={false};
vector<vector <int> >adj(100001);
int var;
void dfs(int v,int col)
{
    int i,j;
    vis[v]=true;
    vi v2;
    //cout<<sz(adj[v])<<endl;
    for(i=0;i<sz(adj[v]);i++)
    {
        if(!vis[adj[v][i]])
        {
            for(j=1;j<=var;j++)
            {
                if(j!=col && j!=c[v] && find(all(v2),j)==v2.end())
                {
                c[adj[v][i]]=j;
                v2.pb(j);
                break;
                }
            }
            dfs(adj[v][i],c[v]);
        }
    }
}
void solve()
{
    int n,i,a,b,siz=-99999;

    cin>>n;

    for(i=1;i<n;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int v;
    for(i=1;i<=n;i++)
        if(sz(adj[i])>siz)
        siz=max(siz,sz(adj[i])),v=i;

    cout<<siz+1<<endl;
    var=siz+1;
    c[v]=1;
    dfs(v,0);
    for(i=1;i<=n;i++)
    cout<<c[i]<<" ";
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define rep(i,a,b)  for( i=a;i<=b;i++)
#define re(i,a,b)  for( i=a;i>=b;i--)
#define pie  2 * acos(0.0)
using namespace std;
void solve();
void dfs(int ,int);
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
 //cin >> T;
 while(T--)
 {solve();
}
}
int c[200001];
bool vis[200001]={false};
vector<vector <int> >adj(200001);
int var;
void dfs(int v,int col)
{
    int i,j;
    vis[v]=true;
    vi v2;
    //cout<<sz(adj[v])<<endl;
    for(i=0;i<sz(adj[v]);i++)
    {
        if(!vis[adj[v][i]])
        {
            for(j=1;j<=var;j++)
            {
                if(j!=col && j!=c[v] && find(all(v2),j)==v2.end())
                {
                c[adj[v][i]]=j;
                v2.pb(j);
                break;
                }
            }
            dfs(adj[v][i],c[v]);
        }
    }
}
void solve()
{
    int n,i,a,b,siz=-99999;

    cin>>n;

    for(i=1;i<n;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int v;
    for(i=1;i<=n;i++)
        if(sz(adj[i])>siz)
        siz=max(siz,sz(adj[i])),v=i;

    cout<<siz+1<<endl;
    var=siz+1;
    c[v]=1;
    dfs(v,0);
    for(i=1;i<=n;i++)
    cout<<c[i]<<" ";
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define rep(i,a,b)  for( i=a;i<=b;i++)
#define re(i,a,b)  for( i=a;i>=b;i--)
#define pie  2 * acos(0.0)
using namespace std;
void solve();
void dfs(int ,int);
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
 //cin >> T;
 while(T--)
 {solve();
}
}
int c[200001];
bool vis[200001]={false};
vector<vector <int> >adj(200001);
int var;
void dfs(int v,int col)
{
    int i,j=1;
    vis[v]=true;
   // unordered_map<int,int> m;
    //cout<<sz(adj[v])<<endl;
    for(i=0;i<sz(adj[v]);i++)
    {
        if(!vis[adj[v][i]])
        {
            for(;j<=var;j++)
            {
                if(j!=col && j!=c[v] )
                {
                c[adj[v][i]]=j;
               // m[j]++;
                j++;
                break;
                }
            }
            dfs(adj[v][i],c[v]);
        }
    }
}
void solve()
{
    int n,i,a,b,siz=-99999;

    cin>>n;

    for(i=1;i<n;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int v;
    for(i=1;i<=n;i++)
        if(sz(adj[i])>siz)
        siz=max(siz,sz(adj[i])),v=i;

    cout<<siz+1<<endl;
    var=siz+1;
    c[v]=1;
    dfs(v,0);
    for(i=1;i<=n;i++)
    cout<<c[i]<<" ";
}


#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353
#define rep(i,a,b)  for( i=a;i<=b;i++)
#define re(i,a,b)  for( i=a;i>=b;i--)
#define pie  2 * acos(0.0)
using namespace std;
void solve();
void dfs(int ,int);
int main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
 //cin >> T;
 while(T--)
 {solve();
}
}
int c[200001];
bool vis[200001]={false};
vector<vector <int> >adj(200001);
int var;
void dfs(int v,int col)
{
    int i,j;
    vis[v]=true;
    unordered_map<int,int> m;
    //cout<<sz(adj[v])<<endl;
    for(i=0;i<sz(adj[v]);i++)
    {
        if(!vis[adj[v][i]])
        {
            for(j=1;j<=var;j++)
            {
                if(j!=col && j!=c[v] && m[j]==0)
                {
                c[adj[v][i]]=j;
                m[j]++;
                break;
                }
            }
            dfs(adj[v][i],c[v]);
        }
    }
}
void solve()
{
    int n,i,a,b,siz=-99999;

    cin>>n;

    for(i=1;i<n;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    int v;
    for(i=1;i<=n;i++)
        if(sz(adj[i])>siz)
        siz=max(siz,sz(adj[i])),v=i;

    cout<<siz+1<<endl;
    var=siz+1;
    c[v]=1;
    dfs(v,0);
    for(i=1;i<=n;i++)
    cout<<c[i]<<" ";
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define lli long long int
#define ll long long
#define inf 1000000000000000000
#define mp make_pair
#define vc vector
#define pq priority_queue
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define FOR(i,n)    for(int i=0;i<n;i++)
#define FOR1(i,a,b) for(int i = a; i<=b; i++)
#define T ll t=0;cin>>t; while(t--)
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
vector <int> v[500001];
vector <vector<int>> v2(101),g2(101);
vector < pair<int,int>>vi[100001];
// vi[x].push_back(make_pair(y,c));
set<int>st;
//st.insert(1);
// int top=*st.begin();
//st.erase(top);
int vis[500001]={0};
int a[100001];
vector<int>arr;
vector<int>ar;
int ma=0;

void dfs(int x,int p)
{
    ma=max(ma,vis[x]);
    int num=1;
    for(int i=0;i<v[x].size();i++)
    {
        int u=v[x][i];
        if(vis[u]==0)
        {
            while(vis[x]==num || vis[p]==num)
                num++;
            vis[u]=num;
            num++;
            dfs(u,x);
        }
    }
}
int main()
{
    fast
    int n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    vis[1]=1;
    dfs(1,0);
    cout<<ma<<endl;
    for(int i=1;i<=n;i++)
        cout<<vis[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define lli long long int
#define ll long long
#define inf 1000000000000000000
#define mp make_pair
#define vc vector
#define pq priority_queue
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define FOR(i,n)    for(int i=0;i<n;i++)
#define FOR1(i,a,b) for(int i = a; i<=b; i++)
#define T int t=0;cin>>t; while(t--)
using namespace std;
//namespace mp=boost::multiprecision;
//mp::cpp_int s=n;
//(atoi(A[i].c_str()));
ifstream in("input.txt");
ofstream out("output.txt");
vector <int> v[500001];
vector <vector<int>> v2(101),g2(101);
vector < pair<int,int>>vi[100001];
set <int> s[1000007];
//ostringstream str;
//strr<<num;
//string s = strr.str();
//a.erase(a.begin()+k);
int dp[100001],vis[100001],f=1;

void dfs(int x,int p)
{
    int y=1;
    for(int i=0;i<v[x].size();i++)
    {
        int u=v[x][i];
        if(vis[u]==0)
        {
            while(vis[x]==y || vis[p]==y)
                l++;
            vis[u]==y++;
            dfs(u,x);
        }
    }
}
int main()
{
    fast
    int n;
    cin>>n;
    FOR(i,n-1)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    memset(vis,0,sizeof(vis));
    vis[1]=1;
    dfs(1,0);
    int ma=0;
    FOR1(i,1,n)
        ma=max(ma,vis[i]);
    cout<<ma<<endl;
    FOR1(i,1,n)
        cout<<vis[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define lli long long int
#define ll long long
#define inf 1000000000000000000
#define mp make_pair
#define vc vector
#define pq priority_queue
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define FOR(i,n)    for(int i=0;i<n;i++)
#define FOR1(i,a,b) for(int i = a; i<=b; i++)
#define T int t=0;cin>>t; while(t--)
using namespace std;
//namespace mp=boost::multiprecision;
//mp::cpp_int s=n;
//(atoi(A[i].c_str()));
ifstream in("input.txt");
ofstream out("output.txt");
vector <int> v[500001];
vector <vector<int>> v2(101),g2(101);
vector < pair<int,int>>vi[100001];
set <int> s[1000007];
//ostringstream str;
//strr<<num;
//string s = strr.str();
//a.erase(a.begin()+k);
int dp[100001],vis[100001],f=1;

void dfs(int x,int p)
{
    int y=1;
    for(int i=0;i<v[x].size();i++)
    {
        int u=v[x][i];
        if(vis[u]==0)
        {
            while(vis[x]==y || vis[p]==y)
                y++;
            vis[u]==y++;
            dfs(u,x);
        }
    }
}
int main()
{
    fast
    int n;
    cin>>n;
    FOR(i,n-1)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    memset(vis,0,sizeof(vis));
    vis[1]=1;
    dfs(1,0);
    int ma=0;
    FOR1(i,1,n)
        ma=max(ma,vis[i]);
    cout<<ma<<endl;
    FOR1(i,1,n)
        cout<<vis[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define lli long long int
#define ll long long
#define inf 1000000000000000000
#define mp make_pair
#define vc vector
#define pq priority_queue
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define FOR(i,n)    for(int i=0;i<n;i++)
#define FOR1(i,a,b) for(int i = a; i<=b; i++)
#define T int t=0;cin>>t; while(t--)
using namespace std;
//namespace mp=boost::multiprecision;
//mp::cpp_int s=n;
//(atoi(A[i].c_str()));
ifstream in("input.txt");
ofstream out("output.txt");
vector <int> v[500001];
vector <vector<int>> v2(101),g2(101);
vector < pair<int,int>>vi[100001];
set <int> s[1000007];
//ostringstream str;
//strr<<num;
//string s = strr.str();
//a.erase(a.begin()+k);
int dp[100001],vis[100001],f=1;

int main()
{
    fast
    int n;
    cin>>n;
    FOR(i,n-1)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    memset(vis,0,sizeof(vis));
    queue<int>q;
    q.push(1);
    vis[1]=1;
    int dp[n+1];
    memset(dp,0,sizeof(dp));
    dp[1]=1;
    vector<int>a;
    while(q.size()>0)
    {
        int n=q.size(),r=1,l=1;
        vector<int>ar;
        FOR(i,n)
        {
            int x=q.front();
            ar.pb(x);
            q.pop();
            for(int j=0;j<v[x].size();j++)
            {
                if(vis[v[x][j]]==0)
                {
                    q.push(v[x][j]);
                    while(dp[l]==1)
                        l++;
                    vis[v[x][j]]=l;
                    dp[l]=1;
                    r++;
                }
            }
        }
        FOR(j,a.size())
            dp[a[j]]=0;
        a=ar;
    }
    int ma=0;
    FOR1(i,1,n)
        ma=max(ma,vis[i]);
    cout<<ma<<endl;
    FOR1(i,1,n)
        cout<<vis[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template<class RIt> void dbarr(RIt frs, RIt lst){ cerr << "arr: "; for(int i = 0; i < (int)(lst-frs); i++) cerr << frs[i] << " \n"[i==(int)(lst-frs)-1]; }
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 2e5+5;
int n,ans[MM],pa[MM];
bool used[MM];
vector<int> adj[MM];

void dfs(int u, int p){
    for(int& v : adj[u]){
        if(v == p) continue;
        pa[v] = u;
        dfs(v,u);
    }
}

void dfs1(int u, int p){
    int ptr = 1;
    int x = ans[u],y = ans[pa[u]];
    for(int& v : adj[u]){
        if(v == p) continue;
        while(ptr == x || ptr == y) ptr++;
        ans[v] = ptr++;
        dfs1(v,u);
    }
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u,v;
        cin >> u >> v;
        adj[u].eb(v); adj[v].eb(u);
    }
    dfs(1,0);
    ans[1] = 1;
    int ptr = 2;
    for(int& v : adj[1]){
        ans[v] = ptr++;
    }
    for(int& v : adj[1]){
        dfs1(v,1);
    }

    int mx = *max_element(ans+1,ans+1+n);
    cout << mx << "\n";
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i==n];
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template<class RIt> void dbarr(RIt frs, RIt lst){ cerr << "arr: "; for(int i = 0; i < (int)(lst-frs); i++) cerr << frs[i] << " \n"[i==(int)(lst-frs)-1]; }
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 2e5+5;
int n,ans[MM],pa[MM];
bool used[MM];
vector<int> adj[MM];

void dfs(int u, int p){
    for(int& v : adj[u]){
        if(v == p) continue;
        pa[v] = u;
        dfs(v,u);
    }
}

void dfs1(int u, int p){
    used[ans[pa[u]]] = 1;
    used[ans[u]] = 1;
    int ptr = 1;
    vector<int> nums;
    for(int i = 0; i < adj[u].size(); i++){
        if(adj[u][i] == p) continue;
        while(used[ptr]) ptr++;
        nums.eb(ptr);
        used[ptr] = 1;
    }
    used[ans[pa[u]]] = 0;
    used[ans[u]] = 0;

    ptr = 0;
    for(int& v : adj[u]){
        if(v == p) continue;
        ans[v] = nums[ptr++];
        used[ans[v]] = 0;
        dfs1(v,u);
    }
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u,v;
        cin >> u >> v;
        adj[u].eb(v); adj[v].eb(u);
    }
    dfs(1,0);
    ans[1] = 1;
    dfs1(1,0);
    int mx = *max_element(ans+1,ans+1+n);
    cout << mx << "\n";
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i==n];
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template<class RIt> void dbarr(RIt frs, RIt lst){ cerr << "arr: "; for(int i = 0; i < (int)(lst-frs); i++) cerr << frs[i] << " \n"[i==(int)(lst-frs)-1]; }
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 2e5+5;
int n,ans[MM],pa[MM];
bool used[MM];
vector<int> adj[MM];

void dfs(int u, int p){
    for(int& v : adj[u]){
        if(v == p) continue;
        pa[v] = u;
        dfs(v,u);
    }
}

void dfs1(int u, int p){
    int ptr = 1;
    for(int& v : adj[u]){
        if(v == p) continue;
        while(ptr == ans[u] || ptr == ans[pa[u]]) ptr++;
        ans[v] = ptr++;
        dfs1(v,u);
    }
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u,v;
        cin >> u >> v;
        adj[u].eb(v); adj[v].eb(u);
    }
    dfs(1,0);
    ans[1] = 1;
    dfs1(1,0);
    int mx = *max_element(ans+1,ans+1+n);
    cout << mx << "\n";
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i==n];
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template<class RIt> void dbarr(RIt frs, RIt lst){ cerr << "arr: "; for(int i = 0; i < (int)(lst-frs); i++) cerr << frs[i] << " \n"[i==(int)(lst-frs)-1]; }
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 2e5+5;
int n,ans[MM],pa[MM];
bool used[MM];
vector<int> adj[MM];

void dfs(int u, int p){
    for(int& v : adj[u]){
        if(v == p) continue;
        pa[v] = u;
        dfs(v,u);
    }
}

void dfs1(int u, int p){
    used[ans[pa[u]]] = 1;
    used[ans[u]] = 1;
    int ptr = 1;
    vector<int> nums;
    for(int i = 0; i < adj[u].size(); i++){
        if(adj[u][i] == p) continue;
        while(used[ptr]) ptr++;
        nums.eb(ptr);
        used[ptr] = 1;
    }
    used[ans[pa[u]]] = 0;
    used[ans[u]] = 0;

    ptr = 0;
    for(int& v : adj[u]){
        if(v == p) continue;
        ans[v] = nums[ptr++];
        dfs1(v,u);
    }
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u,v;
        cin >> u >> v;
        adj[u].eb(v); adj[v].eb(u);
    }
    dfs(1,0);
    ans[1] = 1;
    dfs1(1,0);
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i==n];
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
constexpr int INF = 0x3f3f3f3f; constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
#define db(x) { cerr << #x << " = " << x << endl; }
template<class RIt> void dbarr(RIt frs, RIt lst){ cerr << "arr: "; for(int i = 0; i < (int)(lst-frs); i++) cerr << frs[i] << " \n"[i==(int)(lst-frs)-1]; }
#define all(x) begin(x), end(x)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fs first
#define sn second
const int MM = 2e5+5;
int n,ans[MM],pa[MM];
bool used[MM];
vector<int> adj[MM];

void dfs(int u, int p){
    for(int& v : adj[u]){
        if(v == p) continue;
        pa[v] = u;
        dfs(v,u);
    }
}

void dfs1(int u, int p){
    used[ans[pa[u]]] = 1;
    used[ans[u]] = 1;
    int ptr = 1;
    vector<int> nums;
    for(int i = 0; i < adj[u].size(); i++){
        if(adj[u][i] == p) continue;
        while(used[ptr]) ptr++;
        nums.eb(ptr);
        used[ptr] = 1;
    }
    used[ans[pa[u]]] = 0;
    used[ans[u]] = 0;

    ptr = 0;
    for(int& v : adj[u]){
        if(v == p) continue;
        ans[v] = nums[ptr++];
        dfs1(v,u);
    }
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int u,v;
        cin >> u >> v;
        adj[u].eb(v); adj[v].eb(u);
    }
    dfs(1,0);
    ans[1] = 1;
    dfs1(1,0);
    int mx = *max_element(ans+1,ans+1+n);
    cout << mx << "\n";
    for(int i = 1; i <= n; i++) cout << ans[i] << " \n"[i==n];
}


/**
 * Code your heart out.
 * The Master has failed more times than the beginner has even tried.
 * School Sucks
 */
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e8;
const long long MAX = 1e6;
int color[MAX];
vector<int> adj[MAX];
int n, x, y, ans;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
int adjlist(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}
void dfs(int node, int parent) {
    int cnt = 0;
    for(int element : adj[node]) {
        if(element == parent)continue;
        ++cnt;
        while(color[node] == cnt || color[parent] == cnt) cnt++;
        ans = max(ans, cnt);
        color[element] == cnt;
        dfs(element, node);
    }
}
void solve() {
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> x >> y;
        adjlist(x, y);
    }
    color[1] = 1;
    dfs(1, 0);
    cout << ans << endl;
    for(int i=1; i<=n; i++) {
        cout << color[i] << " ";
    }
}
int main() {
	__fastio;
	solve();
	return 0;
}


/**
 * Code your heart out.
 * The Master has failed more times than the beginner has even tried.
 * School Sucks
 */
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e8;
const long long MAX = 1e6;
vector<int> adj[MAX];
int color[MAX], ans;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
int adjlist(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}
void dfs(int node, int parent) {
    int cnt = 0;
    for(int element : adj[node]) {
        if(element == parent)continue;
        cnt++;
        while(color[node] == cnt || color[parent] == cnt) cnt++;
        ans = max(ans, cnt);
        color[element] = cnt;
        dfs(element, node);
    }
}
void solve() {
    int n;
    cin >> n;
    int x, y;
    for(int i=1; i<n; i++) {
        cin >> x >> y;
        adjlist(x, y);
    }
    color[1] = 1;
    dfs(1, 1);
    cout << ans << endl;
    for(int i=1; i<=n; i++) {
        cout << color[i] << " ";
    }
}
int main() {
	__fastio;
	solve();
	return 0;
}


/**
 * Code your heart out.
 * The Master has failed more times than the beginner has even tried.
 * School Sucks
 */
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e8;
const long long MAX = 1e6;
int color[MAX];
vector<int> adj[MAX];
int n, x, y, ans;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
int adjlist(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}
void dfs(int node, int parent) {
    int cnt = 0;
    for(int element : adj[node]) {
        if(element == parent)continue;
        ++cnt;
        while(color[node] == cnt || color[parent] == cnt) cnt++;
        ans = max(ans, cnt);
        color[element] == cnt;
        dfs(element, node);
    }
}
void solve() {
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> x >> y;
        adjlist(x, y);
    }
    color[1] = 1;
    dfs(1,-1);
    cout << ans << endl;
    for(int i=1; i<=n; i++) {
        cout << color[i] << " ";
    }
}
int main() {
	__fastio;
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define V vector
typedef long long LL;
typedef pair<int, int> pii;
typedef V<int> vi;
typedef V<string> vs;
typedef V<LL> vl;
typedef V<double> vd;
#define forup(i,a,b) for(int i=(a); i<(b); ++i)
#define fordn(i,a,b) for(int i=(a); i>(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define fov(i,a) rep(i,(a).size())
#define foreach(i,X) for(__typeof((X).begin()) i = (X).begin(); i != (X).end(); i++)
#define gi(x) scanf("%d",&x)
#define gl(x) scanf("%I64d",&x)
#define gd(x) scanf("%lf",&x)
#define gs(x) cin >> x
#define pi(x) printf("%d",x)
#define pin(x) printf("%d\n",x)
#define pl(x) printf("%I6d",x)
#define pln(x) printf("%I64d\n",x)
#define ps(s) cout << s;
#define psn(s) cout << s << "\n"
#define pn printf("\n")
#define spc printf(" ")
#define prec(x) cout<<fixed<<setprecision(x)
#define all(x) (x).begin(), (x).end()
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define fr freopen("input.in", "r", stdin)
#define fw freopen("output.out", "w", stdout)
const int inf = numeric_limits<int>::max();
const LL linf = numeric_limits<LL>::max();
const double EPS = 1e-7;
#define MOD 1000000007
#define SPEED ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int main(){
    int n,s,t;
    gi(n);gi(s);gi(t);
    int p[n+1];
    bool v[n+1] = {false} ,found=false;
    forup(i,1,n+1) gi(p[i]);
    int  i = s,count=0;
    while(!v[i])
    {
    	if(i == t) {found = true;break;}
    	v[i] = true;
    	count++;
    	i = p[i];

    }
    if(found==true) pi(count);
    else cout << "-1";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define endl '\n'
#define all(c) (c).begin(),(c).end()
const long long M = (1e9) + 7;
const int N=1e5+1;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cout<<y<<" ";    cout<<'\n';
#define fr first
#define sc second
#define ppb pop_back
int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,s,t,p;
	cin>>n>>s>>t;
	map<int,int> m;
	static int ans;
	if (s==t) {cout<<ans<<endl;return 0;}
	else ans++;
	rep(i,0,n)
	{
		int temp;
		cin>>temp;
		if(s==i+1) {p=temp;}  //p

		m[i+1]=temp;
	}
	if(p==t) {cout<<ans<<endl;return 0;}
	{
		bool OK=0;
		rep(i,0,n)
		{

			debug(p);
			p=m[p];
			ans++;
			if(p==t){OK=1; break;	}
		}
		debug(p);
		if(OK)
		cout<<ans<<endl;
		else
		cout<<-1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define sq(a) (a)*(a);
#define debug(x) std::cerr<<#x<<"="<<x<<'\n'
#define endl '\n'
#define all(c) (c).begin(),(c).end()
const long long M = (1e9) + 7;
const int N=1e5+1;
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pi;
#define cin std::cin
#define cout std::cout
#define vector std::vector
#define pb push_back
#define pv(x) for(auto y:x)    cout<<y<<" ";    cout<<'\n';
#define fr first
#define sc second
#define ppb pop_back
int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,s,t,p;
	cin>>n>>s>>t;
	map<int,int> m;
	rep(i,0,n)
	{
		int temp;
		cin>>temp;
		if(s==i+1) {p=temp;}  //p

		m[i+1]=temp;
	}
	static int ans;
	if(p==t) cout<<ans<<endl;
	else
	{
		bool OK=0;
		ans++;
		rep(i,0,n)
		{

			//debug(p);
			p=m[p];
			ans++;
			if(p==t){OK=1; break;	}
		}
		//debug(p);
		if(OK)
		cout<<ans<<endl;
		else
		cout<<-1<<endl;
	}
	return 0;
}