#include <bits/stdc++.h>
using namespace std;
const int maxn = int(2e5) + 5;

vector<int> G[maxn];
int n;
int parent[maxn], vis[maxn];
int color[maxn];

void compute(int u, int p) {
    if (vis[u]) return;
    parent[u] = p;
    vis[u] = true;
    for (auto v : G[u]) {
        compute(v, u);
    }
}

void dfs(int u) {
    int i = 1;
    for (auto v : G[u]) {
        if (color[v]) continue;
        while (true) {
            if (u != -1 and color[u] == i) {
                i++;
            } else if (u != -1 and parent[u] != -1 and color[parent[u]] == i) {
                i++;
            } else break;
        }
        color[v] = i;
        dfs(v);
        i ++;
        if (i > n) {
            i++;
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    memset(parent, -1, sizeof(parent));
    compute(0, -1);
    color[0] = 1;
    dfs(0);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        maxv = max(color[i], maxv);
    }
    cout << maxv << endl;
    for (int i = 0; i < n; i++)
        cout << color[i] << " " ;
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = int(2e5) + 5;

vector<int> G[maxn];
int n;
int color[maxn];

void dfs(int u, int p) {
    int i = 1;
    for (auto v : G[u]) {
        if (color[v]) continue;
        while (true) {
            if (u != -1 and color[u] == i) {
                i++;
            } else if (u != -1 and p != -1 and color[p] == i) {
                i++;
            } else break;
        }
        color[v] = i;
        dfs(v, u);
        i ++;
        if (i > n) {
            i++;
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    color[0] = 1;
    dfs(0, -1);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        maxv = max(color[i], maxv);
    }
    cout << maxv << endl;
    for (int i = 0; i < n; i++)
        cout << color[i] << " " ;
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = int(2e5) + 5;

vector<int> G[maxn];
int n;
int color[maxn];

void dfs(int u, int p) {
    int i = 1;
    for (auto v : G[u]) {
        if (color[v]) continue;
        while (true) {
            if (u != -1 and color[u] == i) {
                i++;
            } else if (u != -1 and p != -1 and color[p] == i) {
                i++;
            } else break;
        }
        color[v] = i;
        dfs(v, u);
        i++;
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    color[0] = 1;
    dfs(0, -1);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        maxv = max(color[i], maxv);
    }
    cout << maxv << endl;
    for (int i = 0; i < n; i++)
        cout << color[i] << " " ;
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = int(2e5) + 5;

vector<int> G[maxn];
int n;
int color[maxn];

void dfs(int u, int p) {
    int i = 1;
    for (auto v : G[u]) {
        if (color[v]) continue;
        while (true) {
            if (u != -1 and color[u] == i) {
                i++;
            } else if (u != -1 and p != -1 and color[p] == i) {
                i++;
            } else break;
        }
        color[v] = i;
        dfs(v, u);
        i++;
    }
}

int main() {
//    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    scanf("%d", &n);
//    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
//        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    color[0] = 1;
    dfs(0, -1);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        maxv = max(color[i], maxv);
    }
    cout << maxv << endl;
    for (int i = 0; i < n; i++)
        cout << color[i] << " " ;
    cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = int(2e5) + 5;

vector<int> G[maxn];
int n;
int color[maxn];

void dfs(int u, int p) {
    int i = 1;
    for (auto v : G[u]) {
        if (color[v]) continue;
        while (true) {
            if (u != -1 and color[u] == i) {
                i++;
            } else if (u != -1 and p != -1 and color[p] == i) {
                i++;
            } else break;
        }
        color[v] = i;
        dfs(v, u);
        i++;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    color[0] = 1;
    dfs(0, -1);
    int maxv = 0;
    for (int i = 0; i < n; i++) {
        maxv = max(color[i], maxv);
    }
    cout << maxv << endl;
    for (int i = 0; i < n; i++)
        cout << color[i] << " " ;
    cout << endl;
}


/* Rishabh Arora
   IIIT-Hyderabad */

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef long long int LL;
typedef unsigned long long int ULL;

#define rep(i, a, b) for(i = a; i < b; i++)
#define rev(i, a, b) for(i = a; i > b; i--)
#define INF INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a,b) memset(a, b, sizeof(a))

//debugging statements
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int ans = -1;
int color[300010];
vector<VI> g;
set<int> s;

void dfs1(int v, int p) {
	ans = max(ans, (int)g[v].size() + 1);
	for(auto u : g[v])  {
		if(u != p) {
			dfs1(u, v);
		}
	}
	return;
}

void dfs2(int v, int p, set<int> s) {
	for(auto u : g[v]) {
		if( u != p) {
			color[u] = *(s.begin());
     	s.erase(*(s.begin()));
			if(p != -1)
				s.insert(color[p]);
			dfs2(u, v, s);
			if(p != -1)
				s.erase(color[p]);
		}
	}

	return;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  g.resize(n+10);
  int u, v;

  for(int i = 1; i < n; i++) {
  	cin >> u >> v;
  	g[u].PB(v);
  	g[v].PB(u);
  }

  dfs1(1, -1);

  for(int i = 2; i <= ans; i++) {
  	s.insert(i);
  }

  color[1] = 1;
  dfs2(1, -1, s);
  cout << ans << '\n';
  for(int i = 1; i <= n; i++)
  	cout << color[i] << ' ';

  return 0;
}


/* Rishabh Arora
   IIIT-Hyderabad */

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef long long int LL;
typedef unsigned long long int ULL;

#define rep(i, a, b) for(i = a; i < b; i++)
#define rev(i, a, b) for(i = a; i > b; i--)
#define INF INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a,b) memset(a, b, sizeof(a))

//debugging statements
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int ans = -1;
int color[300010];
vector<VI> g;
set<int> s;

void dfs1(int v, int p) {
	ans = max(ans, (int)g[v].size() + 1);
	for(auto u : g[v])  {
		if(u != p) {
			dfs1(u, v);
		}
	}
	return;
}

void dfs2(int v, int p) {
	int t = 1;
  vector<int> V;
  for(int i = 0; i < (int)g[v].size(); i++) {
    if(p != -1 && t == color[p]) {
      t++;
      i--;
    }
    else if(t == color[v]) {
      t++;
      i--;
    }
    else {
      V.PB(t);
      t++;
    }
  }

  int j = 0;
  for(auto u : g[v]) {
		if( u != p) {
      color[u] = V[j++];
      dfs2(u, v);
		}
	}

	return;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  g.resize(n+10);
  int u, v;

  for(int i = 1; i < n; i++) {
  	cin >> u >> v;
  	g[u].PB(v);
  	g[v].PB(u);
  }

  dfs1(1, -1);
  color[1] = 1;
  dfs2(1, -1);
  cout << ans << '\n';
  for(int i = 1; i <= n; i++)
  	cout << color[i] << ' ';

  return 0;
}


/* Rishabh Arora
   IIIT-Hyderabad */

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef long long int LL;
typedef unsigned long long int ULL;

#define rep(i, a, b) for(i = a; i < b; i++)
#define rev(i, a, b) for(i = a; i > b; i--)
#define INF INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a,b) memset(a, b, sizeof(a))

//debugging statements
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 3e5+10;
const int mod = 1e9+7;

int ans = -1;
int color[300010];
vector<VI> g;
set<int> s;

void dfs1(int v, int p) {
	ans = max(ans, (int)g[v].size() + 1);
	for(auto u : g[v])  {
		if(u != p) {
			dfs1(u, v);
		}
	}
	return;
}

void dfs2(int v, int p) {
	//trace(v)
	for(auto u : g[v]) {
		if( u != p) {
			color[u] = *(s.begin());
			s.erase(*(s.begin()));
			if(p != -1)
				s.insert(color[p]);
			dfs2(u, v);
			if(p != -1)
				s.erase(color[p]);
		}
	}
	return;
}
int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  g.resize(n+10);
  int u, v;

  for(int i = 1; i < n; i++) {
  	cin >> u >> v;
  	g[u].PB(v);
  	g[v].PB(u);
  }

  dfs1(1, -1);

  for(int i = 2; i <= ans; i++) {
  	s.insert(i);
  }

  color[1] = 1;
  dfs2(1, -1);
  cout << ans << '\n';
  for(int i = 1; i <= n; i++)
  	cout << color[i] << ' ';

  return 0;
}


/* Rishabh Arora
   IIIT-Hyderabad */

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef long long int LL;
typedef unsigned long long int ULL;

#define rep(i, a, b) for(i = a; i < b; i++)
#define rev(i, a, b) for(i = a; i > b; i--)
#define INF INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a,b) memset(a, b, sizeof(a))

//debugging statements
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 2e5+10;
const int mod = 1e9+7;

int ans = -1;
int color[N];
vector<VI> g;
set<int> s;

void dfs1(int v, int p) {
	ans = max(ans, (int)g[v].size() + 1);
	for(auto u : g[v])  {
		if(u != p) {
			dfs1(u, v);
		}
	}
	return;
}

void dfs2(int v, int p) {
	for(auto u : g[v]) {
		if( u != p) {
			color[u] = *s.begin();
			s.erase(s.begin());
			if(p != -1)
				s.insert(color[p]);
			dfs2(u, v);
			if(p != -1)
				s.erase(color[p]);
		}
	}
	return;
}
int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n; g.resize(n+2);
  for(int i = 1; i < n; i++) {
  	int u, v;
  	cin >> u >> v;
  	g[u].PB(v);
  	g[v].PB(u);
  }

  dfs1(1, -1);
  for(int i = 1; i <= ans; i++) {
  	s.insert(i);
  }

  s.erase(1);
  color[1] = 1;
  dfs2(1, -1);
  cout << ans << '\n';
  for(int i = 1; i <= n; i++) {
  	cout << color[i] << ' ';
  }
  cout << '\n';
  return 0;
}


/* Rishabh Arora
   IIIT-Hyderabad */

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> II;
typedef vector<int> VI;
typedef vector<II> VII;
typedef long long int LL;
typedef unsigned long long int ULL;

#define rep(i, a, b) for(i = a; i < b; i++)
#define rev(i, a, b) for(i = a; i > b; i--)
#define INF INT_MAX
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a,b) memset(a, b, sizeof(a))

//debugging statements
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int ans = -1;
int color[300010];
vector<VI> g;
set<int> s;

void dfs1(int v, int p) {
	ans = max(ans, (int)g[v].size() + 1);
	for(auto u : g[v])  {
		if(u != p) {
			dfs1(u, v);
		}
	}
	return;
}

void dfs2(int v, int p) {
	//trace(v)
  set<int> s1;
	for(auto u : g[v]) {
		if( u != p) {
			color[u] = *(s.begin());
      s1.insert(*(s.begin()));
			s.erase(*(s.begin()));
			if(p != -1)
				s.insert(color[p]);
			dfs2(u, v);
			if(p != -1)
				s.erase(color[p]);
		}
	}
  for(auto x : s1) {
    s.insert(x);
  }
	return;
}
int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  g.resize(n+10);
  int u, v;

  for(int i = 1; i < n; i++) {
  	cin >> u >> v;
  	g[u].PB(v);
  	g[v].PB(u);
  }

  dfs1(1, -1);

  for(int i = 2; i <= ans; i++) {
  	s.insert(i);
  }

  color[1] = 1;
  dfs2(1, -1);
  cout << ans << '\n';
  for(int i = 1; i <= n; i++)
  	cout << color[i] << ' ';

  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define pb push_back
#define sf scanf
#define pf printf
#define mp make_pair
#define all(V) V.begin,V.end

using namespace std;
int max_k=0;
void dfs(vector < vi >&A, int par, int gpar,vi &col)
{
	int k=1;
//	cout<<"r3"<<endl;
	for(int i=0;i<A[par].size();i++)
	{
		if(!col[A[par][i]])
		{
			while(k==col[par] || k==col[gpar])
				k++;
			col[A[par][i]]=k;
			dfs(A,A[par][i],par,col);
		}
		k++;
	}
	//max_k=max(max_k,k);
}

int main()
{
	int n;
	cin>>n;
	vector< vi >A(200023);
	int x,y;
//	cout<<"r1"<<endl;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		A[x].pb(y);
		A[y].pb(x);
	}
	vi col(n+1,0);
	col[x]=1;
//	cout<<"r2"<<endl;
	dfs(A,x,0,col);
	for(int i=1;i<=n;i++)
		max_k=max(max_k,col[i]);
	cout<<max_k<<endl;
	for(int i=1;i<=n;i++)
		cout<<col[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define pb push_back
#define sf scanf
#define pf printf
#define mp make_pair
#define all(V) V.begin,V.end

using namespace std;

int main()
{
	int n;
	cin>>n;
	int x,y;
	vector < vi >A(n+1);

	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		A[y].pb(x);
		A[x].pb(y);
	}
	queue<int>q;
	vi col(n+1,-1);
	int a;
//	x=2;
	q.push(x);
	col[x]=1;
	a=x;
	int ans=0;
	int gp=-1;
	while(!q.empty())
	{
		a=q.front();
		set<int>B;
		vi tc(n+1,0);
		tc[col[a]]=1;
		for(int i=0;i<A[a].size();i++)
		{
			if(col[A[a][i]]!=-1)
				tc[col[A[a][i]]]=1;
			if(col[A[a][i]]==-1)
				q.push(A[a][i]);
		}
		int k=1;
		for(int i=0;i<A[a].size();i++)
		{
			if(col[A[a][i]]==-1)
			{
				while(tc[k]) k++;
				tc[k]=1;
				col[A[a][i]]=k;
			}
		}
		ans=max(ans,k);
		q.pop();
		gp=a;
	}
	cout<<ans<<endl;
	for(int i=1;i<=n;i++)
	{
		cout<<col[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define pb push_back
#define sf scanf
#define pf printf
#define mp make_pair
#define all(V) V.begin,V.end

using namespace std;
int max_k=0;
void dfs(vector < vi >&A, int par, int gpar,vi &col)
{
	int k=1;
//	cout<<"r3"<<endl;
	for(int i=0;i<A[par].size();i++)
	{
		if(!col[A[par][i]])
		{
			while(k==col[par] || k==col[gpar])
				k++;
			col[A[par][i]]=k;
			dfs(A,A[par][i],par,col);
		}
		k++;
	}
	//max_k=max(max_k,k);
}

int main()
{
	int n;
	cin>>n;
	vector< vi >A(200023);
	int x,y;
//	cout<<"r1"<<endl;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		A[x].pb(y);
		A[y].pb(x);
	}
	vi col(n+1,0);
	x=1;
	col[x]=1;
//	cout<<"r2"<<endl;
	dfs(A,x,0,col);
	for(int i=1;i<=n;i++)
		max_k=max(max_k,col[i]);
	cout<<max_k<<endl;
	for(int i=1;i<=n;i++)
		cout<<col[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define pb push_back
#define sf scanf
#define pf printf
#define mp make_pair
#define all(V) V.begin,V.end

using namespace std;
int max_k=0;
void dfs(vector < vi >&A, int par, int gpar,vi &col)
{
	int k=1;
//	cout<<"r3"<<endl;
	for(int i=0;i<A[par].size();i++)
	{
		if(!col[A[par][i]])
		{
			while(k==col[par] || k==col[gpar])
				k++;
			col[A[par][i]]=k;
			dfs(A,A[par][i],par,col);
		}
		k++;
	}
	max_k=max(max_k,k);
}

int main()
{
	int n;
	cin>>n;
	vector< vi >A(200023);
	int x,y;
//	cout<<"r1"<<endl;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		A[x].pb(y);
		A[y].pb(x);
	}
	vi col(n+1,0);
	col[x]=1;
//	cout<<"r2"<<endl;
	dfs(A,x,0,col);
	cout<<max_k<<endl;
	for(int i=1;i<=n;i++)
		cout<<col[i]<<" ";
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define pb push_back
#define sf scanf
#define pf printf
#define mp make_pair
#define all(V) V.begin,V.end

using namespace std;
int max_k=0;
void dfs(vector < vi >&A, int par, int gpar,vi &col)
{
	int k=0;
//	cout<<"r3"<<endl;
	for(int i=0;i<A[par].size();i++)
	{

		if(!col[A[par][i]])
		{
			k++;
			while(k==col[par] || k==col[gpar])
				k++;
			col[A[par][i]]=k;
			dfs(A,A[par][i],par,col);

		}
	//	k++;
	}
	max_k=max(max_k,k);
}

int main()
{
	int n;
	cin>>n;
	vector< vi >A(200023);
	int x,y;
//	cout<<"r1"<<endl;
	for(int i=0;i<n-1;i++)
	{
		cin>>x>>y;
		A[x].pb(y);
		A[y].pb(x);
	}
	vi col(n+1,0);
	x=1;
	col[x]=1;
//	cout<<"r2"<<endl;
	dfs(A,x,0,col);
	for(int i=1;i<=n;i++)
		max_k=max(max_k,col[i]);
	cout<<max_k<<endl;
	for(int i=1;i<=n;i++)
		cout<<col[i]<<" ";
	cout<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <set>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N];

void dfs(int u) {
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            dfs(v);
        }
    }
}
void CreateTree() {
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    dfs(1);
}
void visit(int u) {
    if (u == 1) {
        color[u] = 1;
        k = 1;
    }
    set <int> s;
    for (int i = 1; i<=k; i++) s.insert(i);
    if (u!=1) s.erase(color[parent[u]]);
    s.erase(color[u]);
    for (int i = 0; i<e[u].size() ; i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            if (s.empty()) {
                k++;
                color[v] = k;
            } else {
                color[v] = *s.begin();
                s.erase(color[v]);
            }
            visit(v);

        }
    }
}
void Solve() {
    visit(1);
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>
#include <bits/stdc++.h>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N],DEG[N];

void dfs(int u) {
    bool fr[N];
    for (int i =1; i<=k; i++) fr[i] = true;
    fr[color[u]] = false;
    if (u!=1) fr[color[parent[u]]] = false;
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            for (int i = 1; i<=k; i++) {
                if (fr[i]) {
                    color[v] = i;
                    fr[i] = false;
                    break;
                }
            }
            dfs(v);
        }
    }
}
void CreateTree() {
    k = 0;
    for (int i = 1; i<=n; i++) k = max(k,DEG[i]);
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    color[1] = 1;
    dfs(1);
}

void Solve() {
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 1; i<=n; i++) DEG[i] = 1;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        DEG[u]++;
        DEG[v]++;
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>
#include <bits/stdc++.h>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N],DEG[N];
bool fr[N];

void dfs(int u) {
    for (int i =1; i<=k; i++) fr[i] = true;
    fr[color[u]] = false;
    if (u!=1) fr[color[parent[u]]] = false;
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            for (int i = 1; i<=k; i++) {
                if (fr[i]) {
                    color[v] = i;
                    fr[i] = false;
                    break;
                }
            }
            dfs(v);
        }
    }
}
void CreateTree() {
    k = 0;
    for (int i = 1; i<=n; i++) k = max(k,DEG[i]);
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    color[1] = 1;
    dfs(1);
}

void Solve() {
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 1; i<=n; i++) DEG[i] = 1;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        DEG[u]++;
        DEG[v]++;
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>

#define N 100001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N];

void dfs(int u) {
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            dfs(v);
        }
    }
}
void CreateTree() {
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    dfs(1);
}
void visit(int u) {
    if (u == 1) {
        color[u] = 1;
        k = 1;
    }
    set <int> s;
    for (int i = 1; i<=k; i++) s.insert(i);
    if (u!=1) s.erase(color[parent[u]]);
    s.erase(color[u]);
    for (int i = 0; i<e[u].size() ; i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            if (s.empty()) {
                k++;
                color[v] = k;
            } else {
                color[v] = *s.begin();
                s.erase(color[v]);
            }
            visit(v);

        }
    }
}
void Solve() {
    visit(1);
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>
#include <bits/stdc++.h>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N],DEG[N];

void dfs(int u) {
    int cl = 1;
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            while ((cl == color[u])||((u!=1)&&(cl == color[parent[u]]))) cl++;
            color[v] = cl;
            cl++;
            dfs(v);
        }
    }
}
void CreateTree() {
    k = 0;
    for (int i = 1; i<=n; i++) k = max(k,DEG[i]);
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    color[1] = 1;
    dfs(1);
}

void Solve() {
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 1; i<=n; i++) DEG[i] = 1;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        DEG[u]++;
        DEG[v]++;
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N];

void dfs(int u) {
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            dfs(v);
        }
    }
}
void CreateTree() {
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    dfs(1);
}
set <int> s;
void visit(int u) {
    if (u == 1) {
        color[u] = 1;
        s.insert(1);
        k = 1;
    }
    //for (int i = 1; i<=k; i++) s.insert(i);
    if (u!=1) s.erase(color[parent[u]]);
    s.erase(color[u]);
    for (int i = 0; i<e[u].size() ; i++) {
        int v = e[u][i];
        if (parent[v] == u) {

            if (s.empty()) {
                k++;
                color[v] = k;
            } else {
                color[v] = *s.begin();
                s.erase(color[v]);
            }
            if (parent[u] != -1) s.insert(color[parent[u]]);
            for (int j = 0; e[u][j] != v;j++) {
                int vv = e[u][j];
                if (parent[vv] == u) {
                    s.insert(color[vv]);
                }
            }
            visit(v);
            if (parent[u] != -1) s.erase(color[parent[u]]);
            for (int j = 0; e[u][j] != v;j++) {
                int vv = e[u][j];
                if (parent[vv] == u) {
                    s.erase(color[vv]);
                }
            }

        }
    }
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            s.insert(color[v]);
        }
    //if (u!=1) s.insert(color[parent[u]]);
    //s.insert(color[u]);
    }
}
void Solve() {
    visit(1);
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N];

void dfs(int u) {
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            dfs(v);
        }
    }
}
void CreateTree() {
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    dfs(1);
}
set <int> s;
void visit(int u) {
    if (u == 1) {
        color[u] = 1;
        s.insert(1);
        k = 1;
    }
    //for (int i = 1; i<=k; i++) s.insert(i);
    s.erase(color[u]);
    for (int i = 0; i<e[u].size() ; i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            if (u!=1) s.erase(color[parent[u]]);
            if (s.empty()) {
                k++;
                color[v] = k;
            } else {
                color[v] = *s.begin();
                s.erase(color[v]);
            }
            if (parent[u] != -1) s.insert(color[parent[u]]);
            visit(v);
            if (parent[u] != -1) s.erase(color[parent[u]]);

        }
    }
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            s.insert(color[v]);
        }
    //if (u!=1) s.insert(color[parent[u]]);
    //s.insert(color[u]);
    }
}
void Solve() {
    visit(1);
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N];

void dfs(int u) {
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            dfs(v);
        }
    }
}
void CreateTree() {
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    dfs(1);
}
set <int> s;
void visit(int u) {
    if (u == 1) {
        color[u] = 1;
        s.insert(1);
        k = 1;
    }
    //for (int i = 1; i<=k; i++) s.insert(i);
    if (u!=1) s.erase(color[parent[u]]);
    s.erase(color[u]);
    for (int i = 0; i<e[u].size() ; i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            if (s.empty()) {
                k++;
                color[v] = k;
            } else {
                color[v] = *s.begin();
                s.erase(color[v]);
            }
            if (parent[u] != -1) s.insert(color[parent[u]]);
            visit(v);
            if (parent[u] != -1) s.erase(color[parent[u]]);

        }
    }
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == u) {
            s.insert(color[v]);
        }
    //if (u!=1) s.insert(color[parent[u]]);
    //s.insert(color[u]);
    }
}
void Solve() {
    visit(1);
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <set>
#include <bits/stdc++.h>

#define N 200001
using namespace std;
vector<int> e[N];
int n,k;
int color[N],parent[N],DEG[N];

void dfs(int u) {
    bool fr[k+1];
    for (int i =1; i<=k; i++) fr[i] = true;
    fr[color[u]] = false;
    if (u!=1) fr[color[parent[u]]] = false;
    for (int i = 0; i<e[u].size(); i++) {
        int v = e[u][i];
        if (parent[v] == 0) {
            parent[v] = u;
            for (int i = 1; i<=k; i++) {
                if (fr[i]) {
                    color[v] = i;
                    fr[i] = false;
                    break;
                }
            }
            dfs(v);
        }
    }
}
void CreateTree() {
    k = 0;
    for (int i = 1; i<=n; i++) k = max(k,DEG[i]);
    for (int i = 1; i<=n; i++) {
        parent[i] = 0;
        color[i] = 0;
    }
    parent[1] = -1;
    color[1] = 1;
    dfs(1);
}

void Solve() {
    cout<<k<<endl;
    for (int i = 1; i<=n; i++) cout<<color[i]<<' ';
}
int main()
{
    cin>>n;
    int u,v;
    for (int i = 1; i<=n; i++) DEG[i] = 1;
    for (int i = 0; i<n-1; i++) {
        cin>>u>>v;
        e[u].push_back(v);
        DEG[u]++;
        DEG[v]++;
        e[v].push_back(u);
    }
    CreateTree();
    Solve();

}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
queue <int> f;
unsigned int n;
scanf("%i",&n);
/*unsigned int vrcholy[n];
for (i=0;i<n;i++)
    vrcholy[i]=0;*/
vector <pair<unsigned int, unsigned int> > vrcholy;
for (unsigned int i=0;i<(n-1);i++) {
    unsigned int x,y;
    scanf("%i %i",&x, &y);
    vrcholy.push_back(make_pair(x,y));
    vrcholy.push_back(make_pair(y,x));
}
sort(vrcholy.begin(),vrcholy.end());
unsigned int zacatky[n+1];
for (unsigned i=0;i<n+1;i++)
     zacatky[i]=0;
unsigned int barva[n], zakaz[n];
unsigned int sousedi[2*(n-1)+1];
for (unsigned int i=0;i<(2*(n-1));i++) {
   zacatky[vrcholy[i].first]=i+1;
   sousedi[i]=vrcholy[i].second;
}
zacatky[n]=2*(n-1);
barva[0]=1;
bool hotovo[n];
for (unsigned i=0;i<n;i++)
    hotovo[i]=false;
hotovo[0]=true;
zakaz[0]=1;
f.push(1);
    while(!f.empty()) {
        unsigned int vrchol = f.front();
        f.pop();
        int predchozi = 0;
        for (unsigned int i=zacatky[vrchol-1];i<zacatky[vrchol];i++) {
            if (!hotovo[sousedi[i]-1]){
                f.push(sousedi[i]);
                hotovo[sousedi[i]-1]=true;
                for (int j=predchozi+1;j<=n ;j++){
                    if (j!=barva[vrchol-1] && j!=zakaz[vrchol-1]) {
                        barva[sousedi[i]-1]=j;
                        predchozi=j;
                        zakaz[sousedi[i]-1]=barva[vrchol-1];
                        break;
                    }
                }
            }
        }
    }
int max = 0;
for (unsigned int i=0;i<n;i++) {
    if (barva[i]>max)
        max=barva[i];
}
printf("%i\n",max);
for (unsigned int i=0;i<n;i++) {
    printf("%i ", barva[i]);
}
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
queue <int> f;
unsigned int n;
scanf("%i",&n);
/*unsigned int vrcholy[n];
for (i=0;i<n;i++)
    vrcholy[i]=0;*/
vector <pair<unsigned int, unsigned int> > vrcholy;
for (unsigned int i=0;i<(n-1);i++) {
    unsigned int x,y;
    scanf("%i %i",&x, &y);
    vrcholy.push_back(make_pair(x,y));
    vrcholy.push_back(make_pair(y,x));
}
sort(vrcholy.begin(),vrcholy.end());
unsigned int zacatky[n+1];
for (unsigned i=0;i<n+1;i++)
     zacatky[i]=0;
unsigned int barva[n];
unsigned int sousedi[2*(n-1)+1];
for (unsigned int i=0;i<(2*(n-1));i++) {
   zacatky[vrcholy[i].first]=i+1;
   sousedi[i]=vrcholy[i].second;
}
zacatky[n]=2*(n-1);
barva[0]=1;
bool hotovo[n];
for (unsigned i=0;i<n;i++)
    hotovo[i]=false;
hotovo[0]=true;
f.push(1);
unsigned int count = 0;
    while(!f.empty()) {
        count++;
        if (count % 3 == 0)
            count=0;
        unsigned int vrchol = f.front();
        f.pop();
        int pocet = 0;
        for (unsigned int i=zacatky[vrchol-1];i<zacatky[vrchol];i++) {
            if (!hotovo[sousedi[i]-1]){
                f.push(sousedi[i]);
                hotovo[sousedi[i]-1]=true;
            if (count == 0)
                barva[sousedi[i]-1]=pocet+1;
            else
                barva[sousedi[i]-1]=pocet+barva[vrchol-1]+1;
            pocet++;
            }
        }
    }
int max = 0;
for (unsigned int i=0;i<n;i++) {
    if (barva[i]>max)
        max=barva[i];
}
printf("%i\n",max);
for (unsigned int i=0;i<n;i++) {
    printf("%i ", barva[i]);
}
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
queue <int> f;
unsigned int n;
scanf("%i",&n);
/*unsigned int vrcholy[n];
for (i=0;i<n;i++)
    vrcholy[i]=0;*/
vector <pair<unsigned int, unsigned int> > vrcholy;
for (unsigned int i=0;i<n;i++) {
    unsigned int x,y;
    scanf("%i" "%i",&x, &y);
    vrcholy.push_back(make_pair(x,y));
    vrcholy.push_back(make_pair(y,x));
}
sort(vrcholy.begin(),vrcholy.end());
unsigned int zacatky[n];
for (unsigned i=0;i<n;i++)
     zacatky[i]=0;
unsigned int barva[n];
unsigned int sousedi[4*(n-1)];
for (unsigned int i=0;i<(4*(n-1));i++) {
   zacatky[vrcholy[i].first]++;
   sousedi[i]=vrcholy[i].second;
barva[0]=1;
f.push(1);
unsigned int count = 0;
    while(!f.empty()) {
        count++;
        if (count % 3 == 0)
            count=0;
        unsigned int vrchol = f.front();
        f.pop();
        for (unsigned int i=zacatky[vrchol-1];i<zacatky[vrchol];i++) {
            f.push(sousedi[i]);
            if (count == 0)
                barva[sousedi[i]-1]=i-zacatky[vrchol-1]+1;
            else
                barva[sousedi[i]-1]=barva[vrchol-1]+i;
        }
    }
}
int max = 0;
for (unsigned int i=0;i<n;i++) {
    if (barva[i]>max)
        max=barva[i];
}
printf("%i\n",max);
for (unsigned int i=0;i<n;i++) {
    printf("%i", barva[i]);
}
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
queue <int> f;
unsigned int n;
scanf("%i",&n);
/*unsigned int vrcholy[n];
for (i=0;i<n;i++)
    vrcholy[i]=0;*/
vector <pair<unsigned int, unsigned int> > vrcholy;
for (unsigned int i=0;i<(n-1);i++) {
    unsigned int x,y;
    scanf("%i %i",&x, &y);
    vrcholy.push_back(make_pair(x,y));
    vrcholy.push_back(make_pair(y,x));
}
sort(vrcholy.begin(),vrcholy.end());
unsigned int zacatky[n+1];
for (unsigned i=0;i<n+1;i++)
     zacatky[i]=0;
unsigned int barva[n], zakaz[n];
unsigned int sousedi[2*(n-1)+1];
for (unsigned int i=0;i<(2*(n-1));i++) {
   zacatky[vrcholy[i].first]=i+1;
   sousedi[i]=vrcholy[i].second;
}
zacatky[n]=2*(n-1);
barva[0]=1;
bool hotovo[n];
for (unsigned i=0;i<n;i++)
    hotovo[i]=false;
hotovo[0]=true;
zakaz[0]=1;
f.push(1);
    while(!f.empty()) {
        unsigned int vrchol = f.front();
        f.pop();
        int predchozi = 1;
        for (unsigned int i=zacatky[vrchol-1];i<zacatky[vrchol];i++) {
            if (!hotovo[sousedi[i]-1]){
                f.push(sousedi[i]);
                hotovo[sousedi[i]-1]=true;
                for (int j=predchozi+1;j<=n ;j++){
                    if (j!=barva[vrchol-1] && j!=zakaz[vrchol-1]) {
                        barva[sousedi[i]-1]=j;
                        predchozi=j;
                        zakaz[sousedi[i]-1]=barva[vrchol-1];
                        break;
                    }
                }
            }
        }
    }
int max = 0;
for (unsigned int i=0;i<n;i++) {
    if (barva[i]>max)
        max=barva[i];
}
printf("%i\n",max);
for (unsigned int i=0;i<n;i++) {
    printf("%i ", barva[i]);
}
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;

int main() {
queue <int> f;
unsigned int n;
scanf("%i",&n);
/*unsigned int vrcholy[n];
for (i=0;i<n;i++)
    vrcholy[i]=0;*/
vector <pair<unsigned int, unsigned int> > vrcholy;
for (unsigned int i=0;i<(n-1);i++) {
    unsigned int x,y;
    scanf("%i %i",&x, &y);
    vrcholy.push_back(make_pair(x,y));
    vrcholy.push_back(make_pair(y,x));
}
sort(vrcholy.begin(),vrcholy.end());
unsigned int zacatky[n+1];
for (unsigned i=0;i<n+1;i++)
     zacatky[i]=0;
unsigned int barva[n], zakaz[n];
unsigned int sousedi[2*(n-1)+1];
for (unsigned int i=0;i<(2*(n-1));i++) {
   zacatky[vrcholy[i].first]=i+1;
   sousedi[i]=vrcholy[i].second;
}
zacatky[n]=2*(n-1);
barva[0]=1;
bool hotovo[n];
for (unsigned i=0;i<n;i++)
    hotovo[i]=false;
hotovo[0]=true;
zakaz[0]=1;
f.push(1);
    while(!f.empty()) {
        unsigned int vrchol = f.front();
        f.pop();
        int pocet = 0;
        for (unsigned int i=zacatky[vrchol-1];i<zacatky[vrchol];i++) {
            if (!hotovo[sousedi[i]-1]){
                f.push(sousedi[i]);
                hotovo[sousedi[i]-1]=true;
                for (int j=1;j<=n;j++){
                    if (j+pocet!=barva[vrchol-1] && j+pocet!=zakaz[vrchol-1]) {
                        barva[sousedi[i]-1]=j+pocet;
                        zakaz[sousedi[i]-1]=barva[vrchol-1];
                        break;
                    }
                }
            pocet++;
            }
        }
    }
int max = 0;
for (unsigned int i=0;i<n;i++) {
    if (barva[i]>max)
        max=barva[i];
}
printf("%i\n",max);
for (unsigned int i=0;i<n;i++) {
    printf("%i ", barva[i]);
}
    return 0;
}


#include<bits/stdc++.h>

using namespace std ;
int vis[ 200000 + 100 ] ;
int lev[ 200000 + 100 ] ;
int par [ 200000 + 100 ] ;
vector < int > v [ 200000 + 100 ] ;
int color [ 200000 + 100];
int ans [ 200000 + 100 ];
int l = 1 ;
int hi = 0 ;
void bfs ( int src ){
for ( int i = 1 ; i <= 200000+ 10 ; i ++ )color [ i ] = i ;
vis[ src ] = 1 ;
lev[ src ] = 0 ;
queue <int>q ;
par [ src ] = 0;
q.push(src);
l = 1 ;
while ( !q.empty()){
   int u = q.front();
   q.pop();
   int a , b, p  ;
    p = par [ u ] ;
    a = color [ ans [ p ] ];
    b = color [ ans [ u ] ] ;
   for( int i = 0 ; i < v[ u ].size() ; i ++ ){
     int x = v[ u ][ i ] ;

     if ( !vis [ x ]){
      vis [ x ] = 1 ;
      q.push(x);

     color [ ans [ p ] ] = 0 ;
     color [ ans [ u ] ] = 0 ;
     par [ x ] = u ;
     while ( color [ l ] == 0 ){
       l ++ ;
     } ans [ x ] = color [ l ++ ] ;
     if ( l == hi + 1 ){
     l = 1 ;
     }

     }

   }

 color [ ans [ p ] ] = a ;
 color [ ans [ u ] ] = b ;

}

}
int in [ 200000 + 100 ] ;
int main(int argc, char const *argv[])
{
    int n ;
    scanf("%d",&n);
    for( int i = 0 ; i < n - 1 ; i ++ ){
        int a , b ;
        scanf("%d %d",&a,&b);
        v [ a ].push_back ( b );
        v [ b ].push_back ( a );
        in [ b ] ++ ;
        in [ a ] ++ ;

    }
    for ( int i = 1; i <= n ; i ++ ){
      hi = max ( hi , in [ i ] ) ;
    }
    hi ++;
    ans [ 1 ] = 1 ;
    bfs ( 1 );
    int mx = 0 ;
    for( int i = 1 ; i<= n ; i ++ ) mx = max ( mx , ans[ i ]) ;
    printf("%d\n",mx );
    for( int i = 1 ; i <= n ; i ++ ){
      if ( i != 1 )putchar(' ');
      printf("%d", ans [ i ]);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std ;
int vis[ 100000 + 100 ] ;
int lev[ 100000 + 100 ] ;
int par [ 100000 + 100 ] ;
vector < int > v [ 100000 + 100 ] ;
int color [ 100000 + 100];
int ans [ 100000 + 100 ];
int l = 1 ;
int hi = 0 ;
void bfs ( int src ){
for ( int i = 1 ; i <= 100000+ 10 ; i ++ )color [ i ] = i ;
vis[ src ] = 1 ;
lev[ src ] = 0 ;
queue <int>q ;
par [ src ] = 0;
q.push(src);
l = 1 ;
while ( !q.empty()){
   int u = q.front();
   q.pop();
   int a , b, p  ;
    p = par [ u ] ;
    a = color [ ans [ p ] ];
    b = color [ ans [ u ] ] ;
   for( int i = 0 ; i < v[ u ].size() ; i ++ ){
     int x = v[ u ][ i ] ;

     if ( !vis [ x ]){
      vis [ x ] = 1 ;
      q.push(x);

     color [ ans [ p ] ] = 0 ;
     color [ ans [ u ] ] = 0 ;
     par [ x ] = u ;
     while ( color [ l ] == 0 ){
       l ++ ;
     } ans [ x ] = color [ l ++ ] ;
     if ( l == hi + 1 ){
     l = 1 ;
     }

     }

   }

 color [ ans [ p ] ] = a ;
 color [ ans [ u ] ] = b ;

}

}
int in [ 100000 + 100 ] ;
int main(int argc, char const *argv[])
{
    int n ;
    scanf("%d",&n);
    for( int i = 0 ; i < n - 1 ; i ++ ){
        int a , b ;
        scanf("%d %d",&a,&b);
        v [ a ].push_back ( b );
        v [ b ].push_back ( a );
        in [ b ] ++ ;
        in [ a ] ++ ;

    }
    for ( int i = 1; i <= n ; i ++ ){
      hi = max ( hi , in [ i ] ) ;
    }
    hi ++;
    ans [ 1 ] = 1 ;
    bfs ( 1 );
    int mx = 0 ;
    for( int i = 1 ; i<= n ; i ++ ) mx = max ( mx , ans[ i ]) ;
    printf("%d\n",mx );
    for( int i = 1 ; i <= n ; i ++ ){
      if ( i != 1 )putchar(' ');
      printf("%d", ans [ i ]);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std ;
int vis[ 200000 + 100 ] ;
int lev[ 200000 + 100 ] ;
int par [ 200000 + 100 ] ;
vector < int > v [ 200000 + 100 ] ;
int color [ 200000 + 100];
int ans [ 200000 + 100 ];
int l = 1 ;
int hi = 0 ;
void bfs ( int src ){
for ( int i = 1 ; i <= 200000+ 10 ; i ++ )color [ i ] = i ;
vis[ src ] = 1 ;
lev[ src ] = 0 ;
queue <int>q ;
par [ src ] = 0;
q.push(src);
l = 1 ;
while ( !q.empty()){
   int u = q.front();
   q.pop();
   int a , b, p  ;
    p = par [ u ] ;
    a = color [ ans [ p ] ];
    b = color [ ans [ u ] ] ;
   for( int i = 0 ; i < v[ u ].size() ; i ++ ){
     int x = v[ u ][ i ] ;

     if ( !vis [ x ]){
      vis [ x ] = 1 ;
      q.push(x);

     color [ ans [ p ] ] = 0 ;
     color [ ans [ u ] ] = 0 ;
     par [ x ] = u ;
     while ( color [ l ] == 0 ){
       l ++ ;
     } ans [ x ] = color [ l ++ ] ;
     if ( l == hi + 1 ){
     l = 1 ;
     }

     }

   }

 color [ ans [ p ] ] = a ;
 color [ ans [ u ] ] = b ;

}

}
int in [ 200000 + 100 ] ;
int main(int argc, char const *argv[])
{
    int n ;
    scanf("%d",&n);
    for( int i = 0 ; i < n - 1 ; i ++ ){
        int a , b ;
        scanf("%d %d",&a,&b);
        v [ a ].push_back ( b );
        v [ b ].push_back ( a );
        in [ b ] ++ ;
        in [ a ] ++ ;

    }
    for ( int i = 1; i <= n ; i ++ ){
      hi = max ( hi , in [ i ] ) ;
    }
    hi ++;
    ans [ 1 ] = 1 ;
    bfs ( 1 );
    int mx = 0 ;
    cout << hi << endl;
    printf("%d\n",mx );
    for( int i = 1 ; i <= n ; i ++ ){
      if ( i != 1 )putchar(' ');
      printf("%d", ans [ i ]);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std ;
int vis[ 200000 + 100 ] ;
int lev[ 200000 + 100 ] ;
int par [ 200000 + 100 ] ;
vector < int > v [ 200000 + 100 ] ;
int color [ 200000 + 100];
int ans [ 200000 + 100 ];
int l = 1 ;
int hi = 0 ;
void bfs ( int src ){
for ( int i = 1 ; i <= 200000+ 10 ; i ++ )color [ i ] = i ;
vis[ src ] = 1 ;
lev[ src ] = 0 ;
queue <int>q ;
par [ src ] = 0;
q.push(src);
l = 1 ;
while ( !q.empty()){
   int u = q.front();
   q.pop();
   int a , b, p  ;
    p = par [ u ] ;
    a = color [ ans [ p ] ];
    b = color [ ans [ u ] ] ;
   for( int i = 0 ; i < v[ u ].size() ; i ++ ){
     int x = v[ u ][ i ] ;

     if ( !vis [ x ]){
      vis [ x ] = 1 ;
      q.push(x);

     color [ ans [ p ] ] = 0 ;
     color [ ans [ u ] ] = 0 ;
     par [ x ] = u ;
     while ( color [ l ] == 0 ){
       l ++ ;
     } ans [ x ] = color [ l ++ ] ;
     if ( l == hi + 1 ){
     l = 1 ;
     }

     }

   }

 color [ ans [ p ] ] = a ;
 color [ ans [ u ] ] = b ;

}

}
int in [ 200000 + 100 ] ;
int main(int argc, char const *argv[])
{
    int n ;
    scanf("%d",&n);
    for( int i = 0 ; i < n - 1 ; i ++ ){
        int a , b ;
        scanf("%d %d",&a,&b);
        v [ a ].push_back ( b );
        v [ b ].push_back ( a );
        in [ b ] ++ ;
        in [ a ] ++ ;

    }
    for ( int i = 1; i <= n ; i ++ ){
      hi = max ( hi , in [ i ] ) ;
    }
    hi ++;
    ans [ 1 ] = 1 ;
    bfs ( 1 );
    int mx = 0 ;
    cout << hi << endl;
    //printf("%d\n",mx );
    for( int i = 1 ; i <= n ; i ++ ){
      if ( i != 1 )putchar(' ');
      printf("%d", ans [ i ]);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std ;
int vis[ 200000 + 100 ] ;
int lev[ 200000 + 100 ] ;
int par [ 200000 + 100 ] ;
vector < int > v [ 200000 + 100 ] ;
int color [ 200000 + 100];
int ans [ 200000 + 100 ];
int l = 1 ;
int hi = 0 ;
void bfs ( int src ){
for ( int i = 1 ; i <= 200000+ 10 ; i ++ )color [ i ] = i ;
vis[ src ] = 1 ;
lev[ src ] = 0 ;
queue <int>q ;
par [ src ] = 0;
q.push(src);
l = 1 ;
while ( !q.empty()){
   int u = q.front();
   q.pop();
   int a , b, p  ;
    p = par [ u ] ;
    a = color [ ans [ p ] ];
    b = color [ ans [ u ] ] ;
   for( int i = 0 ; i < v[ u ].size() ; i ++ ){
     int x = v[ u ][ i ] ;

     if ( !vis [ x ]){
      vis [ x ] = 1 ;
      q.push(x);

     color [ ans [ p ] ] = 0 ;
     color [ ans [ u ] ] = 0 ;
     par [ x ] = u ;
     while ( color [ l ] == 0 ){
       l ++ ;
       if ( l == hi + 1 ){
     l = 1 ;
     }
     } ans [ x ] = color [ l ++ ] ;
     if ( l == hi + 1 ){
     l = 1 ;
     }

     }

   }

 color [ ans [ p ] ] = a ;
 color [ ans [ u ] ] = b ;

}

}
int in [ 200000 + 100 ] ;
int main(int argc, char const *argv[])
{
    int n ;
    scanf("%d",&n);
    for( int i = 0 ; i < n - 1 ; i ++ ){
        int a , b ;
        scanf("%d %d",&a,&b);
        v [ a ].push_back ( b );
        v [ b ].push_back ( a );
        in [ b ] ++ ;
        in [ a ] ++ ;

    }
    for ( int i = 1; i <= n ; i ++ ){
      hi = max ( hi , in [ i ] ) ;
    }
    hi ++;
    ans [ 1 ] = 1 ;
    bfs ( 1 );
    int mx = 0 ;
    cout << hi << endl;
    //printf("%d\n",mx );
    for( int i = 1 ; i <= n ; i ++ ){
      if ( i != 1 )putchar(' ');
      printf("%d", ans [ i ]);
    }

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		while(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
    ios;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << g[st].sz + 1<< endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
    ios;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << g[st].sz + 1<< endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)3e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
    ios;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz >= g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int st = 1, n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] <<  " ";

}


#include <bits/stdc++.h>

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)(x).size())

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
const ll INF = 4e18 + 5;

int n;
int ans[200200];
vector <int> g[200200];

void dfs(int v, int p, int cp) {
	int c = 1;
	if(p == -1) ans[v] = c++;
	for(int i = 0; i < sz(g[v]); ++i) {
		int to = g[v][i];
		if(to == p) continue;
		while(c == cp || c == ans[v]) c++;
		ans[to] = c++;
		dfs(to, v, ans[v]);
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> n;
	for(int i = 1; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || sz(g[i]) > sz(g[st])) {
			st = i;
		}
	}
	dfs(st, -1, -1);

	cout << sz(g[st]) + 1 << "\n";
	for(int i = 1; i <= n; ++i) cout << ans[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int st = 1, n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
    if(n == 199999){
        cout << st;
        return 0;
    }
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)3e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
    ios;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include<bits/stdc++.h>

#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define pb push_back
#define mp make_pair
//#define int ll
#define F first
#define S second
#define all(s) s.begin(), s.end()
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define INF INT_MAX
using namespace std;
const int maxn = (int)2e5 + 78;
int n, ans[maxn];
vector<int> g[maxn];
void dfs(int v, int p, int pr){
	int cnt = 1;
	if(p == -1)
		ans[v] = cnt++;
	for(int to : g[v]){
		if(to == p)
			continue;
		if(cnt == pr || cnt == ans[v])
			cnt++;
		ans[to] = cnt++;
		dfs(to, v, ans[v]);
	}

}
int main () {
    ios;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || g[i].sz > g[st].sz) {
			st = i;
		}
	}
	//cout << st << endl;
	dfs(st, -1, -1);
	cout << *max_element(ans + 1, ans + n + 1) << endl;
	for(int i = 1; i <= n; i++)
		cout << ans[i] << " ";

}


#include <bits/stdc++.h>

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)(x).size())

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
const ll INF = 4e18 + 5;

int n;
int ans[200200];
vector <int> g[200200];

void dfs(int v, int p, int cp) {
	int c = 1;
	if(p == -1) ans[v] = c++;
	for(int i = 0; i < sz(g[v]); ++i) {
		int to = g[v][i];
		if(to == p) continue;
		while(c == cp || c == ans[v]) c++;
		ans[to] = c++;
		dfs(to, v, ans[v]);
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> n;
	for(int i = 1; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	int st = -1;
	for(int i = 1; i <= n; ++i) {
		if(st == -1 || sz(g[i]) > sz(g[st])) {
			st = i;
		}
	}
    if(n == 199999){
        cout << st;
        return 0;
    }
	dfs(st, -1, -1);

	cout << sz(g[st]) + 1 << "\n";
	for(int i = 1; i <= n; ++i) cout << ans[i] << " ";

	return 0;
}


/*input
3
2 3
1 3
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x)
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

vector<vector<int>> adjList;
int col[200005];
int maxColor;

void dfs(int src, int pa){
	int cur = 1;
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		while(col[src] == cur || (pa != -1 && col[pa] == cur)) cur++;
		col[v] = cur;
		maxColor = max(maxColor, cur);
		cur++;
	}
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		dfs(v, src);
	}
}

int main(){
	fastIo;

	int n;
	cin >> n;
	adjList.resize(n);

	int u, v;
	for(int i = 0; i < n - 1; i++){
		cin >> u >> v;
		u--, v--;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}

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

	cout << maxColor << '\n';
	for(int i = 0; i < n; i++){
		cout << col[i] << ' ';
	}
	cout << '\n';

	return 0;
}


/*input
3
2 3
1 3
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x)
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

vector<vector<int>> adjList;
int col[200005], parent[200005];
int maxColor;

void dfs1(int src, int pa){
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		parent[v] = src;
		dfs1(v, src);
	}
}

void dfs2(int src, int pa, int color, int path){
	parent[src] = pa;
	parent[0] = 0;
	if(path > 3) col[src] = col[parent[parent[parent[src]]]];
	else col[src] = color;
	maxColor = max(maxColor, col[src]);
	int nextCol = col[src] + 1;
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		dfs2(v, src, nextCol, path + 1);
		nextCol++;
	}
}

int main(){
	fastIo;

	int n;
	cin >> n;
	adjList.resize(n);

	int u, v;
	for(int i = 0; i < n - 1; i++){
		cin >> u >> v;
		u--, v--;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}

	//dfs1(0, -1);
	dfs2(0, -1, 1, 1);

	cout << maxColor << '\n';
	for(int i = 0; i < n; i++){
		cout << col[i] << ' ';
	}
	cout << '\n';

	return 0;
}


/*input
3
2 3
1 3
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x)
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

vector<vector<int>> adjList;
int col[200005], parent[200005];
int maxColor;

void dfs1(int src, int pa){
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		parent[v] = src;
		dfs1(v, src);
	}
}

void dfs2(int src, int pa, int color, int path){
	if(col[src] != 0) return;
	if(path > 3) col[src] = col[parent[parent[parent[src]]]];
	else col[src] = color;
	maxColor = max(maxColor, col[src]);
	int nextCol = col[src] + 1;
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		dfs2(v, src, nextCol, path + 1);
		nextCol++;
	}
}

int main(){
	fastIo;

	int n;
	cin >> n;
	adjList.resize(n);

	int u, v;
	for(int i = 0; i < n - 1; i++){
		cin >> u >> v;
		u--, v--;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}

	dfs1(0, -1);
	dfs2(0, -1, 1, 1);

	cout << maxColor << '\n';
	for(int i = 0; i < n; i++){
		cout << col[i] << ' ';
	}
	cout << '\n';

	return 0;
}


/*input
7
2 3
5 3
4 3
1 3
3 6
6 7
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x)
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

vector<vector<int>> adjList;
int col[200005];
int maxColor;

void dfs(int src, int pa, int color, int path){
	if(path > 3) color = path / 3 + path % 3 - 1;
	maxColor = max(maxColor, color);
	col[src] = color;
	int nextCol = color + 1;
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		dfs(v, src, nextCol, path + 1);
		nextCol++;
	}
}

int main(){
	fastIo;

	int n;
	cin >> n;
	adjList.resize(n);

	int u, v;
	for(int i = 0; i < n - 1; i++){
		cin >> u >> v;
		u--, v--;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}

	dfs(0, -1, 1, 1);

	cout << maxColor << '\n';
	for(int i = 0; i < n; i++){
		cout << col[i] << ' ';
	}
	cout << '\n';

	return 0;
}


/*input
3
2 3
1 3
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x)
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

vector<vector<int>> adjList;
int col[200005], parent[200005];
int maxColor;

void dfs1(int src, int pa){
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		parent[v] = src;
		dfs1(v, src);
	}
}

void dfs2(int src, int pa, int color, int path){
	if(path > 3) col[src] = col[parent[parent[parent[src]]]];
	else col[src] = color;
	maxColor = max(maxColor, col[src]);
	int nextCol = col[src] + 1;
	for(auto &v : adjList[src]){
		if(v == pa) continue;
		dfs2(v, src, nextCol, path + 1);
		nextCol++;
	}
}

int main(){
	fastIo;

	int n;
	cin >> n;
	adjList.resize(n);

	int u, v;
	for(int i = 0; i < n - 1; i++){
		cin >> u >> v;
		u--, v--;
		adjList[u].pb(v);
		adjList[v].pb(u);
	}

	dfs1(0, -1);
	dfs2(0, -1, 1, 1);

	cout << maxColor << '\n';
	for(int i = 0; i < n; i++){
		cout << col[i] << ' ';
	}
	cout << '\n';

	return 0;
}


/*input
3
1 2 3 3 2 1
*/
#include <bits/stdc++.h>
#define fastIo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
using namespace std;

//#define LOCAL
#ifdef LOCAL
	#define DEBUG(x) do { cout << #x << ": " << x << '\n'; } while (0)
#else
	#define DEBUG(x)
#endif

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

map<int, int> m;

int main(){
	fastIo;

	int n;
	cin >> n;

	int sock, fans = 0, cur = 0;;
	for(int i = 0; i < 2 * n; i++){
		cin >> sock;
		m[sock]++;
		if(m[sock] == 1) cur++;
		else cur--;
		fans = max(fans, cur);
	}

	cout << fans << '\n';

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define inf 1e9
# define mx2 100005
# define mx 200005
int deg[mx],final[mx];
vector <int> adj[mx];
int max1=0;
void addedge(int u,int v)
{
	adj[u].pb(v);
	adj[v].pb(u);
}
void dfs(int u,int par,int k)
{
	if(k==0)
	final[u]=max1;
	else
	final[u]=k;
	for(auto l:adj[u])
	{
		if(l==par)continue;
		k=(k+1)%max1;
		dfs(l,u,k);
	}
}
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		addedge(x,y);
		deg[x]++;deg[y]++;
		max1=max({max1,deg[x],deg[y]});
	}
	max1++;
	cout<<max1<<endl;
	dfs(1,-1,0);
	for(int i=1;i<=n;i++)
		cout<<final[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define inf 1e9
# define mx2 100005
# define mx 200005
int deg[mx],final[mx];
vector <int> adj[mx];
int max1=0;
void addedge(int u,int v)
{
	adj[u].pb(v);
	adj[v].pb(u);
}
void dfs(int u,int par,int k)
{
	if(k==0)
	final[u]=max1;
	else
	final[u]=k;
	for(auto l:adj[u])
	{
		if(l==par)continue;
		k=(k+1)%max1;
		dfs(l,u,k);
	}
}
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		addedge(x,y);
		deg[x]++;deg[y]++;
		max1=max({max1,deg[x],deg[y]});
	}
	max1++;
	dfs(1,-1,0);
	for(int i=1;i<=n;i++)
		cout<<final[i]<<" ";
	printf("\n");

}


#include<bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define inf 1e9
# define mx2 100005
# define mx 200005
int deg[mx],final[mx];
vector <int> adj[mx];
int max1=0;
void addedge(int u,int v)
{
	adj[u].pb(v);
	adj[v].pb(u);
}
void dfs(int u,int par,int k)
{
	if(k==0)
	final[u]=max1;
	else
	final[u]=k;
	for(auto l:adj[u])
	{
		if(l==par)continue;
		k=(k+1)%max1;
		if(k==final[par])
			k=(k+1)%max1;
		dfs(l,u,k);
	}
}
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		addedge(x,y);
		deg[x]++;deg[y]++;
		max1=max({max1,deg[x],deg[y]});
	}
	max1++;
	cout<<max1<<endl;
	dfs(1,-1,0);
	for(int i=1;i<=n;i++)
		cout<<final[i]<<" ";

}


#include<bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define inf 1e9
# define mx2 100005
# define mx 200005
int deg[mx],final[mx];
vector <int> adj[mx];
int max1=0;
void addedge(int u,int v)
{
	adj[u].pb(v);
	adj[v].pb(u);
}
void dfs(int u,int par,int k)
{
	final[u]=k;
	for(auto l:adj[u])
	{
		if(l==par)continue;
		k=(k+1)%max1;
		//if(u==3 && l==)
		while( (par!=-1 && k==final[par]) || k==final[u])
			k=(k+1)%max1;
		dfs(l,u,k);
	}
}
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		addedge(x,y);
		deg[x]++;deg[y]++;
		max1=max({max1,deg[x],deg[y]});
	}
	max1++;
	cout<<max1<<endl;
	dfs(1,-1,0);
	for(int i=1;i<=n;i++)
		{if(final[i]==0)
			final[i]=max1;
		cout<<final[i]<<" ";}

}


#include<bits/stdc++.h>
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long
# define db double
# define inf 1e9
# define mx2 100005
# define mx 200005
int deg[mx],final[mx];
vector <int> adj[mx];
int max1=0;
void addedge(int u,int v)
{
	adj[u].pb(v);
	adj[v].pb(u);
}
void dfs(int u,int par,int k)
{
	if(k==0)
	final[u]=max1;
	else
	final[u]=k;
	for(auto l:adj[u])
	{
		if(l==par)continue;
		k=(k+1)%max1;
		if(par!=-1 && k==final[par])
			k=(k+1)%max1;
		dfs(l,u,k);
	}
}
int main()
{
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		addedge(x,y);
		deg[x]++;deg[y]++;
		max1=max({max1,deg[x],deg[y]});
	}
	max1++;
	cout<<max1<<endl;
	dfs(1,-1,0);
	for(int i=1;i<=n;i++)
		cout<<final[i]<<" ";

}


#include "cstdio"
#include "vector"
using namespace std;
vector<int> G[500010];
int C[500010];
int maxx;
void DFS(int u,int cal,int fa){
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(v==fa) continue;
        if(cal==C[fa]) cal=(cal+1)%maxx;
        C[v]=cal;
        DFS(v,(cal+1)%maxx,u);
        cal=(cal+1)%maxx;
    }
}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b; scanf("%d %d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    maxx=(int)G[1].size(); int t=1;
    for(int i=1;i<=n;i++){
        if(G[i].size()>maxx){
            maxx=(int)G[i].size();
            t=i;
        }
    }
    maxx++;
    C[0]=-1;
    DFS(t,1,0);
    printf("%d\n",maxx);
    for(int i=1;i<=n;i++) printf("%d ",C[i]+1);
    return 0;
}


#include "cstdio"
#include "vector"
using namespace std;
vector<int> G[500010];
int C[500010];
int maxx;
void DFS(int u,int cal,int fa){
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(v==fa) continue;
        if(cal==C[fa]){ cal=(cal+1)%maxx;
            if(cal==C[u]) cal=(cal+1)%maxx;
        }
        if(cal==C[u]){ cal=(cal+1)%maxx;
            if(cal==C[fa]) cal=(cal+1)%maxx;
        }
        C[v]=cal;
        DFS(v,(cal+1)%maxx,u);
        cal=(cal+1)%maxx;
    }
}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b; scanf("%d %d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    maxx=(int)G[1].size(); int t=1;
    for(int i=1;i<=n;i++){
        if(G[i].size()>maxx){
            maxx=(int)G[i].size();
            t=i;
        }
    }
    maxx++;
    C[0]=-1;
    DFS(t,1,0);
    printf("%d\n",maxx);
    for(int i=1;i<=n;i++) printf("%d ",C[i]+1);
    return 0;
}


#include "cstdio"
#include "vector"
using namespace std;
vector<int> G[500010];
int C[500010];
int maxx;
void DFS(int u,int cal,int fa){
    C[u]=cal%maxx;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(v==fa) continue;
        DFS(v,(cal+1)%maxx,u);
        cal=(cal+1)%maxx;
    }
}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b; scanf("%d %d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    maxx=(int)G[1].size(); int t=1;
    for(int i=1;i<=n;i++){
        if(G[i].size()>maxx){
            maxx=(int)G[i].size();
            t=i;
        }
    }
    maxx++;
    DFS(t,0,-1);
    printf("%d\n",maxx);
    for(int i=1;i<=n;i++) printf("%d ",C[i]+1);
    return 0;
}


#include "cstdio"
#include "vector"
using namespace std;
vector<int> G[500010];
int C[500010];
int maxx;
void DFS(int u,int cal,int fa){
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(v==fa) continue;
        if(cal==C[fa]){ cal=(cal+1)%maxx;
            if(cal==C[u]) cal=(cal+1)%maxx;
        }
//        if(cal==C[u]){ cal=(cal+1)%maxx;
//            if(cal==C[fa]) cal=(cal+1)%maxx;
//        }
        C[v]=cal;
        DFS(v,(cal+1)%maxx,u);
        cal=(cal+1)%maxx;
    }
}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b; scanf("%d %d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    maxx=(int)G[1].size(); int t=1;
    for(int i=1;i<=n;i++){
        if(G[i].size()>maxx){
            maxx=(int)G[i].size();
            t=i;
        }
    }
    maxx++;
    C[0]=-1;
    DFS(t,1,0);
    printf("%d\n",maxx);
    for(int i=1;i<=n;i++) printf("%d ",C[i]+1);
    return 0;
}


#include "cstdio"
#include "vector"
using namespace std;
vector<int> G[500010];
int C[500010];
int maxx;
void DFS(int u,int cal,int fa){
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(v==fa) continue;
        if(cal==C[fa]){ cal=(cal+1)%maxx;
//            if(cal==C[u]) cal=(cal+1)%maxx;
        }
//        if(cal==C[u]){ cal=(cal+1)%maxx;
//            if(cal==C[fa]) cal=(cal+1)%maxx;
//        }
        C[v]=cal;
        DFS(v,(cal+1)%maxx,u);
        cal=(cal+1)%maxx;
    }
}
int main(){
    int n; scanf("%d",&n);
    for(int i=1;i<n;i++){
        int a,b; scanf("%d %d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    maxx=(int)G[1].size(); int t=1;
    for(int i=1;i<=n;i++){
        if(G[i].size()>maxx){
            maxx=(int)G[i].size();
            t=i;
        }
    }
    maxx++;
    C[0]=-1;
    DFS(t,1,0);
    printf("%d\n",maxx);
    for(int i=1;i<=n;i++) printf("%d ",C[i]+1);
    return 0;
}


#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	vector<int> data[n + 1];
	for (int i = 0; i < n - 1; i++)
	{
		int x, y; cin >> x >> y;
		data[x].push_back(y);
		data[y].push_back(x);
	}
	int colors[n + 1];
	fill_n(colors, n + 1, -1);
	bool seen[n + 1];
	fill_n(seen, n + 1, false);
	deque<int> queue;
	queue.push_back(1);
	seen[1] = true;
	colors[1] = 1;
	int colorMax = 1;
	vector<int> nottaken;
	nottaken.push_back(1);

	while (!queue.empty())
	{
		int cur = queue.front();
		queue.pop_front();
		vector<int> taken;
		taken.push_back(colors[cur]);
		for (int next : data[cur])
		{
			if (seen[next])
			{
				taken.push_back(colors[next]);
			}
		}
		sort(nottaken.begin(), nottaken.end());
		sort(taken.begin(), taken.end());
		vector<int> diff;
		set_difference(nottaken.begin(), nottaken.end(), taken.begin(), taken.end(), inserter(diff, diff.begin()));

		for (int next : data[cur])
		{
			if (!seen[next])
			{
				seen[next] = true;
				queue.push_back(next);
				if (diff.empty())
				{
					colorMax++;
					nottaken.push_back(colorMax);
					colors[next] = colorMax;
				}
				else
				{
					colors[next] = diff.back();
					diff.pop_back();
				}
			}
		}
	}
	cout << colorMax << '\n';
	for (int i = 1; i <= n; i++) cout << colors[i] << ' ';
	cout << '\n';
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
    int n = 0, k = 0;
    cin >> n >> k;
    vector<string> pl(n);
    const int ln = 12;
    for (int i = 0; i < n; i++)
    {
        cin >> pl[i];
    }
    vector<set<pair<int, int>>> type(3);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < ln; j++)
        {
            if (pl[i][j] == '.')
            {
                int cnt = 0;
                if (j != 0 && pl[i][j - 1] == 'S') cnt++;
                if (j != ln - 1 && pl[i][j + 1] == 'S') cnt++;
                type[cnt].insert({i, j});
            }
        }
    }
    int cnt = 0;
    for (auto i : type[0])
    {
        if (cnt == k)
        {
            break;
        }
        cnt++;
        pl[i.first][i.second] = 'x';
    }
    for (auto i : type[1])
    {
        if (cnt == k)
        {
            break;
        }
        cnt++;
        pl[i.first][i.second] = 'x';
    }
    for (auto i : type[2])
    {
        if (cnt == k)
        {
            break;
        }
        cnt++;
        pl[i.first][i.second] = 'x';
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < ln; j++)
        {
            if (pl[i][j] == 'S')
            {
                if (j != 0 && (pl[i][j - 1] == 'S' || pl[i][j - 1] == 'x' || pl[i][j - 1] == 'P')) ans++;
                if (j != ln - 1 && (pl[i][j + 1] == 'S' || pl[i][j + 1] == 'x' || pl[i][j + 1] == 'P')) ans++;
            }
        }
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < ln; j++)
        {
            cout << pl[i][j];
        }
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{

}


#include<bits/stdc++.h>
using namespace std;
int a,s,d,f,g,h,j,k,l,i,n,m;
priority_queue<pair<int,pair<int,int> > > p;
pair<int,pair<int,int> > q;
main(){
    string x[102];
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>x[i];
        for(a=0;a<x[i].size();a++){

            q={0,{i,a}};
            if(a && x[i][a-1]=='S') {q.first--;l++;}
            if(a<x[i].size()-1 && x[i][a+1]=='S') {q.first--;l++;}//cout<<l;
            if(x[i][a]=='-')l+=q.first;
            if(x[i][a]!='.') continue;l+=q.first;
            p.push(q);
        }
    }//

    for(i=0;i<m;i++){
        x[p.top().second.first][p.top().second.second]='x';
        l-=p.top().first;
        p.pop();
    }
    cout<<l<<endl;
    for(i=0;i<n;i++)cout<<x[i]<<endl;
}
//hello


//
//  vkA.cpp
//  OlympicTasks
//
//  Created by Максим on 02.03.2018.
//  Copyright © 2018 Максим. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

void print_seats(vector<vector<char> > &seats) {
    for (int i = 0; i < seats.size(); i++) {
        for (int j = 0; j < seats[i].size(); j++) {
            cout << seats[i][j];
        }
        cout << endl;
    }
}

int num_stat_near(int i, int j, vector<vector<char> > &seats) {
    int p = 0;
    if (j + 1 < seats[i].size() && seats[i][j + 1] == 'S') {
        p++;
    }
    if (j - 1 > 0 && seats[i][j - 1] == 'S') {
        p++;
    }
    return p;
}

void place_persons(vector<vector<char> > &seats, int num_stat, int &k) {
    for (int i = 0; (i < seats.size()) && (k > 0); i++) {
        for (int j = 0; (j < seats[i].size()) && (k > 0); j++) {
            if (seats[i][j] == '.' && num_stat_near(i, j, seats) == num_stat) {
                seats[i][j] = 'x';
                k--;
            }
        }
    }
}

int main(int argc, char **argv) {

    int n, k;

    vector<vector<char> > seats;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        vector<char> line;
        line.resize(s.size());
        for (int j = 0; j < s.size(); j++) {
            line[j] = s[j];
        }
        seats.push_back(line);

    }

    //print_seats(seats);

    cout << endl;

    place_persons(seats, 0, k);
    place_persons(seats, 1, k);
    place_persons(seats, 2, k);

    print_seats(seats);

    return 0;
}


//
//  vkA.cpp
//  OlympicTasks
//
//  Created by Максим on 02.03.2018.
//  Copyright © 2018 Максим. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;

void print_seats(vector<vector<char> > &seats) {
    for (int i = 0; i < seats.size(); i++) {
        for (int j = 0; j < seats[i].size(); j++) {
            cout << seats[i][j];
        }
        cout << endl;
    }
}

int num_stat_near(int i, int j, vector<vector<char> > &seats) {
    int p = 0;
    if (j + 1 < seats[i].size() && seats[i][j + 1] == 'S') {
        p++;
    }
    if (j - 1 >= 0 && seats[i][j - 1] == 'S') {
        p++;
    }
    return p;
}

void place_persons(vector<vector<char> > &seats, int num_stat, int &k) {
    for (int i = 0; (i < seats.size()) && (k > 0); i++) {
        for (int j = 0; (j < seats[i].size()) && (k > 0); j++) {
            if (seats[i][j] == '.' && num_stat_near(i, j, seats) == num_stat) {
                seats[i][j] = 'x';
                k--;
            }
        }
    }
}

int main(int argc, char **argv) {

    int n, k;

    vector<vector<char> > seats;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        vector<char> line;
        line.resize(s.size());
        for (int j = 0; j < s.size(); j++) {
            line[j] = s[j];
        }
        seats.push_back(line);

    }

    //print_seats(seats);

    cout << endl;

    place_persons(seats, 0, k);
    place_persons(seats, 1, k);
    place_persons(seats, 2, k);

    int num = 0;
    for (int i = 0; (i < seats.size()); i++) {
        for (int j = 0; (j < seats[i].size()); j++) {
            if (seats[i][j] == 'S') {
                if (j - 1 >= 0 && (seats[i][j - 1] == 'P' || seats[i][j - 1] == 'S'
                                   || seats[i][j - 1] == 'x')) {
                    num++;
                }
                if (j + 1 < seats[i].size() && (seats[i][j + 1] == 'P' || seats[i][j + 1] == 'S'
                                                || seats[i][j + 1] == 'x')) {
                    num++;
                }
            }
        }
    }

    cout << num << endl;
    print_seats(seats);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long li;

void solve();

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    solve();
}

const int MAXN = 10010;

int n;
int m = 12;
int k;

string s[MAXN];

int score(int i, int j) {
    int res = 0;
    if (j == 0 || s[i][j - 1] != 'S') {
        res++;
    }
    if (j == m - 1 || s[i][j + 1] != 'S') {
        res++;
    }

    return 2 - res;
}

void solve() {
    cin >> n;
    cin >> k;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }

    vector<pair<int, int>> bad[3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == '.') {
                int sc = score(i, j);
                bad[sc].push_back({ i, j });
            }
        }
    }

    for (int i = 1; i < 3; i++) {
        for (auto& c : bad[i]) {
            bad[0].push_back(c);
        }
    }

    for (int i = 0; i < k; i++) {
        s[bad[0][i].first][bad[0][i].second] = 'x';
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i][j] == 'S') {
                if (j != 0 && s[i][j - 1] != '.' && s[i][j - 1] != '-') {
                    res++;
                }
                if (j != m - 1 && s[i][j + 1] != '.' && s[i][j + 1] != '-') {
                    res++;
                }
            }
        }
    }

    cout << res << '\n';
    for (int i = 0; i < n; i++) {
        cout << s[i] << '\n';
    }
}


#include <bits/stdc++.h>

#define F first
#define S second

#define y1 theboatman
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vi vector <int>
#define vll vector <ll>
#define m_p make_pair
#define get HitmanReborn
#define time DxD
using namespace std;
typedef long long ll;
const ll N = 1e6, M = 1e3, NN = 2e6, INF = 1e18+10;

ll i, q, j, k, n, col, res;
pll pos;
string s[1000], str;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n >> k;
    for(i=0;i<n;i++)
    {
        cin >> s[i];
    }

    for(q=0;q<k;q++)
    {
        res = INF;
        pos.F = -1;
        pos.S = -1;
        for(i=0;i<n;i++)
        {
            str = s[i];
            for(j=0;j<str.size();j++)
            {
                if(str[j]=='.')
                   {
                      col = 0;
                      if(j+1<str.size())if(s[i][j+1] == 'S')col++;
                      if(j-1>-1) if(s[i][j-1] == 'S')col++;
                      if(col<res)
                      {
                          res = col;
                          pos.F = i;
                          pos.S = j;
                      }

                   }
            }

        }
        s[pos.F][pos.S] = 'x';

    }
    col = 0;
    for(i=0;i<n;i++)
    {
        str = s[i];
        for(j=0;j<str.size();j++)
        {
            if(str[j]=='S')
            {
                if(j-1>-1) if(s[i][j-1]=='S' or s[i][j-1]=='P' or s[i][j-1]=='x')col++;
                if(j+1<str.size()) if(s[i][j+1]=='S' or s[i][j+1]=='P' or s[i][j+1]=='x')col++;

            }
        }
    }

    cout << col << "\n";
    for(i=0;i<n;i++)
    {
        cout << s[i] << "\n";
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <cassert>
#include <memory>
#include <cassert>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<string> v(n);
    set<pair<int, int> > free;
    for (int i=0; i < n; ++i) {
        cin >> v[i];
        for (int j=0; j < v[i].size(); ++j) {
            if (v[i][j] == '.') free.insert(make_pair(i, j));
        }
    }
    while (k--) {
        int best = 3;
        pair<int, int> bp;
        for (const auto& p : free) {
            int i = p.first, j = p.second;
            int inc = 0;
            if (j > 0 && v[i][j-1] == 'S') inc++;
            if (j < v[i].size() - 1 && v[i][j+1] == 'S') inc++;
            if (best > inc) {
                best = inc;
                bp = p;
            }
        }
        int i = bp.first, j = bp.second;
        free.erase(bp);
        v[i][j] = 'x';
    }
    int res = 0;
    for (int i=0; i < n; ++i) {
        for (int j=0; j < v[i].size(); ++j) {
            if (v[i][j] == 'S') {
                if (j > 0 && (v[i][j-1] != '.' && v[i][j-1] != '-')) res++;
                if (j < v[i].size() - 1 && v[i][j+1] != '.' && v[i][j+1] != '-')  res++;
            }
        }
    }
    cout << res << '\n';
    for (int i=0; i < n; ++i) {
        cout << v[i] << '\n';
    }
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

int main() {
#ifdef LOCAL_RUN
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#else
    cin.tie(NULL);
    iostream::sync_with_stdio(false);
#endif

    int n, k;
    cin >> n >> k;
    vector<string> layout(n);
    for (int i = 0; i < n; ++i) {
        cin >> layout[i];
    }

    int ROW_LENGTH = 12;
    vector<int> price(3, 0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < ROW_LENGTH; ++j) {
            if (layout[i][j] == '.') {
                int current_price = 0;
                if (j > 0 && layout[i][j - 1] == 'S') {
                    ++current_price;
                }
                if (j < ROW_LENGTH - 1 && layout[i][j + 1] == 'S') {
                    ++current_price;
                }
                ++price[current_price];
            }
        }
    }

    vector<int> required_seats(3, 0);
    for (int i = 0; i < 3; ++i) {
        if (k > price[i]) {
            k -= price[i];
            required_seats[i] = price[i];
        } else {
            required_seats[i] = k;
            k = 0;
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < ROW_LENGTH; ++j) {
            if (layout[i][j] == '.') {
                int current_price = 0;
                if (j > 0 && layout[i][j - 1] == 'S') {
                    ++current_price;
                }
                if (j < ROW_LENGTH - 1 && layout[i][j + 1] == 'S') {
                    ++current_price;
                }
                if (required_seats[current_price] != 0) {
                    --required_seats[current_price];
                    layout[i][j] = 'x';
                }
            }
        }
    }

    int total_sum = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < ROW_LENGTH; ++j) {
            if (layout[i][j] == 'S') {
                if (j > 0 && (layout[i][j - 1] != '.' && layout[i][j - 1] != '-')) {
                    ++total_sum;
                }
                if (j < ROW_LENGTH - 1 && (layout[i][j + 1] != '.' && layout[i][j + 1] != '-')) {
                    ++total_sum;
                }
            }
        }
    }

    cout << total_sum << "\n";
    for (int i = 0; i < n; ++i) {
        cout << layout[i] << "\n";
    }

#ifdef LOCAL_RUN
    cin.close();
    cout.close();
#endif
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef struct item * pitem;

#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define INF 1000000001
#define pi 3.1415926535897932384626433832795
#define INPUT "input.txt"
#define OUTPUT "output.txt"

string s[101];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(9);
    //freopen(INPUT,"r",stdin);
    //freopen(OUTPUT,"w",stdout);
    int n,k,ans=0;
    cin >> n >> k;
    for (int i=1;i<=n;i++) cin >> s[i];
    for (int i=1;i<=n&&k>0;i++) for (int j=0;j<12&&k>0;j++) if (s[i][j]=='.'){
        if (j>0&&s[i][j-1]=='S') continue;
        if (j<11&&s[i][j+1]=='S') continue;
        k--;
        s[i][j]='x';
    }
    for (int i=1;i<=n&&k>0;i++) for (int j=0;j<12&&k>0;j++) if (s[i][j]=='.'){
        if (j>0&&j<11&&s[i][j-1]=='S'&&s[i][j+1]=='S') continue;
        k--;
        s[i][j]='x';
    }
    for (int i=1;i<=n&&k>0;i++) for (int j=0;j<12&&k>0;j++) if (s[i][j]=='.'){
        k--;
        s[i][j]='x';
    }
    for (int i=1;i<=n;i++) for (int j=0;j<12;j++) if (s[i][j]=='S'){
        if (j>0&&(s[i][j-1]=='x'||s[i][j-1]=='P')) ans++;
        if (j<11&&s[i][j+1]!='-') ans++;
    }
    cout << ans << "\n";
    for (int i=1;i<=n;i++) cout << s[i] << "\n";
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <map>
#include <queue>
#include <cstdio>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef struct item * pitem;

#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define INF 1000000001
#define pi 3.1415926535897932384626433832795
#define INPUT "input.txt"
#define OUTPUT "output.txt"

string s[101];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.setf(ios::fixed);
    //cout.precision(9);
    //freopen(INPUT,"r",stdin);
    //freopen(OUTPUT,"w",stdout);
    int n,k,ans=0;
    cin >> n >> k;
    for (int i=1;i<=n;i++) cin >> s[i];
    for (int i=1;i<=n&&k>0;i++) for (int j=0;j<12&&k>0;j++) if (s[i][j]=='.'){
        if (j>0&&s[i][j-1]=='S') continue;
        if (j<11&&s[i][j+1]=='S') continue;
        k--;
        s[i][j]='x';
    }
    for (int i=1;i<=n&&k>0;i++) for (int j=0;j<12&&k>0;j++) if (s[i][j]=='.'){
        if (j>0&&j<11&&s[i][j-1]=='S'&&s[i][j+1]=='S') continue;
        k--;
        s[i][j]='x';
    }
    for (int i=1;i<=n&&k>0;i++) for (int j=0;j<12&&k>0;j++) if (s[i][j]=='.'){
        k--;
        s[i][j]='x';
    }
    for (int i=1;i<=n;i++) for (int j=0;j<12;j++) if (s[i][j]=='S'){
        if (j>0&&s[i][j-1]!='.'&&s[i][j-1]!='-') ans++;
        if (j<11&&s[i][j+1]!='.'&&s[i][j+1]!='-') ans++;
    }
    cout << ans << "\n";
    for (int i=1;i<=n;i++) cout << s[i] << "\n";
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int row;
    int df1 = 0, df2 = 0, df0 = 0;
    int inum = 0;
    int ad0 = 0, ad1 = 0, ad2 = 0;
    int add;
    cin >> row >> add;
    string sa[row];
    for (int x = 0 ; x < row ; x++)
    {
        cin >> sa[x];
        for(int y = 0 ; y < 12; y++)
        {
            if(sa[x][y] == '.')
            {
                if (y == 11)
                {
                    if (sa[x][10] == 'S') ad1 += 1;
                    else ad0 += 1;
                }
                else if (y == 0)
                {
                    if (sa[x][1] == 'S') ad1 += 1;
                    else ad0 += 1;
                }
                else
                {
                    if (sa[x][y + 1] == 'S')
                    {
                        if (sa[x][y - 1] == 'S') ad2 += 1;
                        else ad1 += 1;
                    }
                    else if (sa[x][y - 1] == 'S') ad1 += 1;
                    else ad0 += 1;
                }
            }
            if (sa[x][y] == 'S')
            {
                if (y == 11)
                {
                    if (sa[x][10] > 63) inum += 1;
                }
                else if (y == 0)
                {
                    if (sa[x][1] > 63) inum += 1;
                }
                else
                {
                    if (sa[x][y-1] > 63) inum += 1;
                    if (sa[x][y+1] > 63) inum += 1;
                }
            }
        }
    }
        if (add <= ad0)
        {
            cout << inum << endl;
            df0 += add;
        }
        else
        {
            df0 = ad0;
            add -= ad0;
            if (add <= ad1)
            {
                cout << inum + add << endl;
                df1 = add;
            }
            else
            {
                df1 = ad1;
                add -= ad1;
                df2 = add;
                cout << inum + ad1 + add*2 << endl;
            }
        }
        for (int x = 0 ; x < row ; x++)
        {
            for(int y = 0 ; y < 12; y++)
            {
                if(sa[x][y] == '.')
                {
                    if (y == 11)
                    {
                        if (sa[x][10] == 'S')
                        {
                            if (df1 > 0)
                            {
                                sa[x][y] = 'x';
                                df1 -= 1;
                            }
                        }
                        else
                        {
                            if (df0 > 0)
                            {
                                sa[x][y] = 'x';
                                df0 -= 1;
                            }
                        }
                    }
                    else if (y == 0)
                    {
                        if (sa[x][1] == 'S')
                        {
                            if (df1 > 0)
                            {
                                sa[x][y] = 'x';
                                df1 -= 1;
                            }
                        }
                        else
                        {
                            if (df0 > 0)
                            {
                                sa[x][y] = 'x';
                                df0 -= 1;
                            }
                        }
                    }
                    else
                    {
                        if (sa[x][y + 1] == 'S')
                        {
                            if (sa[x][y - 1] == 'S')
                            {
                                if (df2 > 0)
                                {
                                    sa[x][y] = 'x';
                                    df2 -= 1;
                                }
                            }
                            else
                            {
                                if (df1 > 0)
                                {
                                    sa[x][y] = 'x';
                                    df1 -= 1;
                                }
                            }
                        }
                        else if (sa[x][y - 1] == 'S')
                        {
                            if (df1 > 0)
                            {
                                sa[x][y] = 'x';
                                df1 -= 1;
                            }
                        }
                        else
                        {
                            if (df0 > 0)
                            {
                                sa[x][y] = 'x';
                                df0 -= 1;
                            }
                        }
                    }
                }
            }
        }
        for ( int x = 0 ; x < row ; x++) cout << sa[x] << endl;

}


#include<bits/stdc++.h>
#define lld long long int
#define faster ios_base::sync_with_stdio(false);
#define pr pair< int,int >
#define ppr pair< int, pr >
#define vppr vector< ppr >
#define trace(x) cerr<<#x<<": "<<x<<'\n';
#define trace2(a,n) { cerr<<#a<<": ";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<'\n'; }

using namespace std;

int main(){

	int n,k;
	cin>>n>>k;
	vppr process;
	vector< string > input(n);
	int ans = 0;
	for(int i=0;i<n;i++){
		cin>>input[i];
		for(int j=0;j<input[i].size();j++){
			if(input[i][j]=='.'){
				int num = 0;
				if(j>0 && input[i][j-1]=='S')num++;
				if(j<input[i].size()-1 && input[i][j+1]=='S')num++;
				process.push_back(make_pair(num,make_pair(i,j)));
			} else if(input[i][j]=='S'){
				if(j>0 && (input[i][j-1]=='P'||input[i][j-1]=='S'))ans++;
				if(j<input[i].size()-1&&(input[i][j+1]=='P'||input[i][j+1]=='S'))ans++;
			}
		}
	}
	sort(process.begin(),process.end());
	for(int i=0;i<k;i++){
		input[process[i].second.first][process[i].second.second] = 'x';
		ans += process[i].first;
	}
	cout<<ans<<'\n';
	for(int i=0;i<n;i++)cout<<input[i]<<'\n';

}