#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }
    ll fl=0;
    fo(i,n)
    {
        if(a[i]!=c[i]){
            fl=1;
            break;
        }
    }
    if(fl==0){
        cout<<0<<endl;
        return;
    }
    ll tmp=0;
    for(ll i=n-2;i>=1;i--){
            if(a[i]<a[i-1]&&a[i]<a[i+1]){
                tmp=i;
                break;
            }

    }
    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }

    ll tmp=n-1;

    for(ll i=n-1;i>=0;i--){
        if(a[i]<=a[i-1])
            tmp--;
        else
            break;
    }
    for(ll i=tmp;i>=0;i--){
        if(a[i]>=a[i-1])
            tmp--;
        else
            break;
    }

    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }
    ll fl=0;
    fo(i,n)
    {
        if(a[i]!=c[i]){
            fl=1;
            break;
        }
    }
    if(fl==0){
        cout<<0<<endl;
        return;
    }

    ll tmp=0;
    for(ll i=n-2;i>=1;i--){
            if(i!=(n-2)&&a[i]<a[i-1]&&a[i]<=a[i+1]){

                tmp=i;
                break;
            }

    }

    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }

    ll tmp=0;
    for(ll i=n-2;i>=1;i--){
            if(a[i]<a[i-1]&&a[i]<a[i+1]){
                tmp=i;
                break;
            }
            else if(a[i]<a[i-1]&&a[i]==a[i+1]&&a[i]<a[n-1]){
                tmp=i;
                break;
            }

    }
    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }

    ll tmp=0;
    for(ll i=n-2;i>=1;i--){
            if(a[i]<a[i-1]&&a[i]<a[i+1]){

                tmp=i;
                break;
            }
            else if(i!=(n-2)&&a[i]<a[i-1]&&a[i]<=a[i+1]){
                tmp=i;
                break;
            }

    }

    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }

    ll tmp=n-1;

    for(ll i=n-1;i>=1;i--){
        if(a[i]<=a[i-1])
            tmp--;
        else
            break;
    }
    for(ll i=tmp;i>=1;i--){
        if(a[i]>=a[i-1])
            tmp--;
        else
            break;
    }

    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }
    ll fl=0;
    fo(i,n)
    {
        if(a[i]!=c[i]){
            fl=1;
            break;
        }
    }
    if(fl==0){
        cout<<0<<endl;
        return;
    }
    ll tmp=0;
    for(ll i=n-2;i>=1;i--){
            if(a[i]<a[i-1]&&a[i]<a[i+1]){
                tmp=i;
                break;
            }
            else if(a[i]<a[i-1]&&a[i]<a[n-1]){
                tmp=i;
                break;
            }

    }
    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
#define fo(iter,n)	    for(ll iter=0;iter<n;iter++)
#define foc(iter,s,e)	for(ll iter=s;iter<=e;iter++)
#define fob(iter,s,e)	for(ll iter=s;iter>=e;iter--)
#define MOD				(ll)1000000007
#define pp				pair<ll,ll>
#define vii				vector<int>
#define vll				vector<ll>
#define vpp				vector<pp>
#define vss				vector<string>
#define take(A,n)		{fo(iter,n)cin>>A[iter];}
#define pb				push_back
#define pob				pop_back
#define eb				emplace_back
#define pf				push_front
#define pof				pop_front
#define mkp				make_pair
#define all(a)			a.begin(),a.end()
#define ff				first
#define ss				second
#define lcm(a,b)		(a*b)/__gcd(a,b)
#define bs(v,x)			binary_search(all(v),x)
#define ub(v,x)			upper_bound(all(v),x)
#define lb(v,x)			lower_bound(all(v),x)
#define FIO			    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pi              ld(3.14159265358979323846)
void pr(ll x){cout<<x;}
void prt(ll x){cout<<x<<endl;}

void sol()
{
    ll n;
    cin>>n;
    ll a[n];
    ll c[n];
    fo(i,n)
    {
        cin>>a[i];
        c[i]=a[i];
    }
    sort(c,c+n);
    if(n==1||n==2){
        cout<<0<<endl;
        return;
    }
    ll fl=0;
    fo(i,n)
    {
        if(a[i]!=c[i]){
            fl=1;
            break;
        }
    }
    if(fl==0){
        cout<<0<<endl;
        return;
    }

    ll tmp=0;
    for(ll i=n-2;i>=1;i--){
            if(a[i]<a[i-1]&&a[i]<=a[i+1]){

                tmp=i;
                break;
            }

    }

    prt(tmp);

}

int main()
{
    FIO;
    ll T=1;
    cin>>T;

    while(T--)
    {

       sol();
    }

    return 0;
    }


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for (auto &it : a) cin >> it;
		int pos = n - 1;
		while (pos > 0 && a[pos - 1] >= a[pos]) --pos;
		while (pos > 0 && a[pos - 1] <= a[pos]) --pos;
		cout << pos << endl;
	}

	return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]>=arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<=arr[i+1] && arr[j-1]<arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>=arr[i+1] && arr[j-1]<=arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]>=arr[i+1] && arr[j-1]>arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]<arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]==arr[i+1] && arr[i]<arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[j]==arr[j-1] && arr[i]>arr[j])
    {
        return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]==arr[i+1] && arr[i]==arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]<arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for (auto &it : a) cin >> it;
		int pos = n - 1;
		while (pos > 0 && a[pos - 1] >= a[pos])
		{
		       --pos;
		}
		while (pos > 0 && a[pos - 1] <= a[pos])
		{
		       --pos;
		}
		cout << pos << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vector<int> a(n);
		for (auto &it : a) cin >> it;
		int pos = n - 1;
		while (pos > 0 && a[pos - 1] >= a[pos]) pos--;
		while (pos > 0 && a[pos - 1] <= a[pos]) pos--;
		cout << pos << endl;
	}

	return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]>arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]<arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]<arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]>=arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<=arr[i+1] && arr[j-1]<arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]<arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]>=arr[i+1] && arr[j-1]>arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]<=arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]<arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]=>arr[i+1] && arr[j-1]>arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]<=arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]<arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


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

using namespace std;

int check(int i,int j,vector<int> &arr,int &cnt)
{

     if(i>=j)
     {
         return cnt;
     }

     int n=arr.size();

    if(i+1<n && j-1>=0 && arr[i]>arr[i+1] && arr[j-1]>arr[j])
    {
       return check(i,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]<arr[j])
    {
        return check(i+1,j,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]<arr[i+1] && arr[j-1]>arr[j])
    {
        return check(i+1,j-1,arr,cnt);
    }
    else if(i+1<n && j-1>=0 && arr[i]>=arr[i+1] && arr[j-1]<=arr[j])
    {
      cnt++;
      return check(cnt,arr.size()-1,arr,cnt);
    }

}
int main()
{
    int t;
    cin>>t;

    while(t--)
    {
       int n;
       cin>>n;

       vector<int>arr(n);

       for(int i=0;i<n;i++)
       {
           cin>>arr[i];
       }

       int i=0;
       int j=n-1;

       int cnt=0;

       cout<<check(i,j,arr,cnt)<<endl;

    }
    return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,1),rh(n,1);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=1;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=1;
		}

		int ans=INT_MAX;
		for(int i=1;i<n;i++){
			if(i==n-1){
				ans=min(ans,n-lh[i]);
				continue;
			}
			if(lh[i-1]+rh[i+1]+1==n){
				ans=0;
				break;
			}
			if(rh[i+1]==n-i-1){
			    if(arr[i-1]>arr[i]){
			        ans=min(ans,n-rh[i+1]-1);
			    }
				else{
				    ans=min(ans,n-rh[i+1]-lh[i-1]-1);
				}
			}
// 			cout<<ans<<" "<<i<<endl;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,0),rh(n,0);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=0;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=0;
		}

		int ans=n;
		for(int i=0;i<n-1;i++){
			if(lh[i-1]+rh[i+1]+1==n-1){
				ans=0;
				break;
			}
			if(rh[i+1]+1==n-i-1){
			    if(i==0){
			        ans=min(ans,n-rh[i]);
			        continue;
			    }
				ans=min(ans,n-rh[i+1]-lh[i]-1);
			}
		}
		ans<=0?ans=1:ans;
		cout<<ans-1<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,1),rh(n,1);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		if(n==2){
			if(arr[0]<=arr[1]){
				cout<<0<<endl;
			}else{
				cout<<1<<endl;
			}
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=1;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=1;
		}

		int ans=INT_MAX;
		for(int i=1;i<n-1;i++){
// 			if(i==n-1){
// 				ans=min(ans,n-lh[i]);
// 				continue;
// 			}
			if(lh[i-1]+rh[i+1]+1==n){
				ans=0;
				break;
			}
			if(rh[i+1]==n-i-1){
			    if(arr[i-1]>arr[i]){
			        ans=min(ans,n-rh[i+1]-1);
			    }
				else{
				    ans=min(ans,n-rh[i+1]-lh[i-1]-1);
				}
			}
// 			cout<<ans<<" "<<i<<endl;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,1),rh(n,1);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1 || n==2){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=1;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=1;
		}

		int ans=INT_MAX;
		for(int i=1;i<n;i++){
			if(i==n-1){
				ans=min(ans,n-lh[i]);
				continue;
			}
			if(lh[i-1]+rh[i+1]+1==n){
				ans=0;
				break;
			}
			if(rh[i+1]==n-i-1){
			    if(arr[i-1]>arr[i]){
			        ans=min(ans,n-rh[i+1]-1);
			    }
				else{
				    ans=min(ans,n-rh[i+1]-lh[i-1]-1);
				}
			}
// 			cout<<ans<<" "<<i<<endl;
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,0),rh(n,0);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=0;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=0;
		}

		int ans=n;
		for(int i=1;i<n-1;i++){
			if(lh[i-1]+rh[i+1]+1==n-1){
				ans=0;
				break;
			}
			if(rh[i+1]+1==n-i-1){
				ans=min(ans,n-rh[i+1]-lh[i]-1);
			}
		}
		cout<<ans-1<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,1),rh(n,1);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=1;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=1;
		}

		int ans=n-1;
		for(int i=1;i<n-1;i++){

			if(lh[i-1]+rh[i+1]+1==n){
				ans=0;
				break;
			}
			if(rh[i+1]==n-i-1){
				ans=min(ans,n-rh[i+1]-lh[i]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,0),rh(n,0);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=0;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=0;
		}

		int ans=INT_MAX;
		for(int i=1;i<n-1;i++){
// 			if(i==n-1){
// 				ans=min(ans,n-lh[i]);
// 				continue;
// 			}
			if(lh[i-1]+rh[i+1]+1==n-1){
				ans=0;
				break;
			}
			if(rh[i+1]+1==n-i-1){
				ans=min(ans,n-rh[i+1]-lh[i]-1);
			}
		}
		cout<<ans-1<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		//n=1,2;
		vector<int>arr(n),lh(n,1),rh(n,1);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		if(n==2){
			if(arr[0]<=arr[1]){
				cout<<0<<endl;
			}else{
				cout<<1<<endl;
			}
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=1;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=1;
		}
		int ans=INT_MAX;
		for(int i=1;i<n-1;i++){
			if(lh[i-1]+rh[i+1]+1==n){
				ans=0;
				break;
			}
			if(rh[i+1]==n-i-1){
				ans=i;
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int>arr(n),lh(n,1),rh(n,1);
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		if(n==1){
			cout<<0<<endl;
			continue;
		}
		for(int i=1;i<n;i++){
			arr[i]>=arr[i-1]?lh[i]=1+lh[i-1]:lh[i]=1;
		}
		for(int i=n-2;i>=0;i--){
			arr[i]>=arr[i+1]?rh[i]=1+rh[i+1]:rh[i]=1;
		}

		int ans=n-1;
		for(int i=0;i<n;i++){
			if(lh[i]+rh[i]-1==n){
				ans=0;
				break;
			}
			if(rh[i]==n-i){
				ans=min(ans,n-rh[i]-lh[i]+1);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


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

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;
	unordered_set<int> front;
	unordered_set<int> back;

	while (!queue.empty())
	{
		swap(front, back);
		int cur = queue.front();
		queue.pop_front();
		front.erase(colors[cur]);
		back.insert(colors[cur]);
		for (int next : data[cur])
		{
			if (seen[next])
			{
				front.erase(colors[next]);
				back.insert(colors[next]);
			}
		}
		for (int next : data[cur])
		{
			if (!seen[next])
			{
				seen[next] = true;
				queue.push_back(next);
				if (front.empty())
				{
					colorMax++;
					back.insert(colorMax);
					colors[next] = colorMax;
				}
				else
				{
					int color = *(front.begin());
					colors[next] = color;
					front.erase(color);
					back.insert(color);
				}
			}
		}
		back.insert(front.begin(), front.end());
		front.clear();
	}
	cout << colorMax << '\n';
	for (int i = 1; i <= n; i++) cout << colors[i] << ' ';
	cout << '\n';
	return 0;
}


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

using namespace std;

int main()
{
	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 <deque>
#include <algorithm>
#include <set>

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;
	set<int> front;
	set<int> back;

	while (!queue.empty())
	{
		swap(front, back);
		int cur = queue.front();
		queue.pop_front();
		front.erase(colors[cur]);
		back.insert(colors[cur]);
		for (int next : data[cur])
		{
			if (seen[next])
			{
				front.erase(colors[next]);
				back.insert(colors[next]);
			}
		}
		for (int next : data[cur])
		{
			if (!seen[next])
			{
				seen[next] = true;
				queue.push_back(next);
				if (front.empty())
				{
					colorMax++;
					back.insert(colorMax);
					colors[next] = colorMax;
				}
				else
				{
					int color = *(front.begin());
					colors[next] = color;
					front.erase(color);
					back.insert(color);
				}
			}
		}
		back.insert(front.begin(), front.end());
		front.clear();
	}
	cout << colorMax << '\n';
	for (int i = 1; i <= n; i++) cout << colors[i] << ' ';
	cout << '\n';
	return 0;
}


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

using namespace std;

void dfs(vector<int>* graph, int parent, int cur, bool* seen, int* colors)
{
    seen[cur] = true;
    int curColor = colors[cur];
    int parColor = colors[parent];
    int color = 1;
    for (int next : graph[cur])
    {
        if (!seen[next])
        {
            while (color == curColor || color == parColor) color++;
            colors[next] = color;
            color++;
            dfs(graph, cur, next, seen, colors);
        }
    }
}

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);
    colors[1] = 1;
    dfs(data, 0, 1, seen, colors);
    int maxColor = colors[1];
    for (int i = 2; i <= n; i++) maxColor = max(maxColor, colors[i]);
    cout << maxColor << '\n';
    for (int i = 1; i <= n; i++) cout << colors[i] << ' ';
    cout << '\n';
    return 0;
}


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

using namespace std;

int main()
{
	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;
	set<int> nottaken;
	nottaken.insert(1);
	set<int> taken;

	while (!queue.empty())
	{
		int cur = queue.front();
		queue.pop_front();
		taken.clear();
		taken.insert(colors[cur]);
		for (int next : data[cur])
		{
			if (seen[next])
			{
				taken.insert(colors[next]);
			}
		}
		set<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.insert(colorMax);
					colors[next] = colorMax;
				}
				else
				{
					int color = *(diff.begin());
					colors[next] = color;
					diff.erase(color);
				}
			}
		}
	}
	cout << colorMax << '\n';
	for (int i = 1; i <= n; i++) cout << colors[i] << ' ';
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int n,i,j,ans,INF=1e9+7,maxn=1,b[200005];
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    for (int i=1;i<=max(me[p].size(),me[x].size())+1;i++)
    {
        if (me[x].end()==me[x].find(i) && me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int n,i,j,ans,INF=1e9+7,maxn=1,b[200005];
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    int r=INF;
    if (me[x].size())r=min(r,*me[x].begin());
    else if (me[p].size())r=min(r,*me[p].begin());
    else r=1;
    for (int i=r;i<=max(me[p].size(),me[x].size())+1;i++)
    {
        if (me[x].end()==me[x].find(i) && me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int maxn=0,b[200005],k;
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    int k1=k;
    for (int i=k-1;i>0;i--)
    {
        if (me[x].find(i)==me[x].end()  && me[p].find(i)==me[p].end()){me[x].insert(i);b[x]=i;k=i;break;}
    }
    if (k==k1)
    {
        for (int i=k+1;i<=maxn+1;i++)
        {
            if (me[x].find(i)==me[x].end() && me[p].find(i)==me[p].end()){me[x].insert(i);b[x]=i;k=i;break;}
        }
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    int n;
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
ill n,i,j,ans,INF=1e9+7;
double maxn=INF*1.0,l,r;
pair < ill , ill > my[60005];
int main()
{
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>my[i].fi;
    }
    for (i=1;i<=n;i++)
    {
        cin>>my[i].se;
    }
    sort (my+1,my+n+1);
    l=my[1].fi*1.0;
    r=my[n].fi*1.0;
    while (l<r-0.00000000000001)
    {
        double m=(l+r)/2.0;
        double a=0.0,b=0.0;
        for (i=1;i<=n;i++)
        {
            if (my[i].fi<=m){a=max((abs(m-my[i].fi))/(my[i].se),a);}
            if (my[i].fi>=m){b=max(b,(abs(m-my[i].fi))/(my[i].se));}
        }
        maxn=min(maxn,max(a,b));
        if (a>b)r=m;
        else l=m;
    }
    cout<<fixed<<setprecision(15)<<maxn<<endl;
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int n,maxn=0,b[200005],k;
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    int k1=k;
    for (int i=k;i>0;i--)
    {
        if (me[p].find(i)==me[p].end()){me[x].insert(i);b[x]=i;k=i;break;}
    }
    if (k==k1)
    {
        for (int i=k;i<=n;i++)
        {
            if (me[p].find(i)==me[p].end()){me[x].insert(i);b[x]=i;k=i;break;}
        }
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int maxn=0,b[200005];
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    for (int i=1;i<=maxn+1;i++)
    {
        if (me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    int n;
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int maxn=0,b[200005];
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    for (int i=1;i<=max(me[p].size(),me[x].size())+1;i++)
    {
        if (me[x].end()==me[x].find(i) && me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    int n;
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int n,i,j,ans,INF=1e9+7,maxn=1,b[200005];
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    for (int i=1;i<=max(me[p].size(),me[x].size())+1;i++)
    {
        if (me[x].end()==me[x].find(i) && me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int maxn=0,b[200005];
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    for (int i=1;i<=maxn+1;i++)
    {
        if (me[x].end()==me[x].find(i) && me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (b[v]==0){dfs(v,x);}
    }
}
int main()
{
    int n;
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int n,maxn=0,b[200005],k;
vector <int> my[200005];
set<int> me[200005];
void dfs(int x,int p)
{
    int k=1;
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        if (v==p)continue;
        while (k==b[x] || k==b[p])k++;
        maxn=max(maxn,k);
        b[v]=k;
        k++;
        dfs(v,x);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    b[1]=1;
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#define ill int long long
#define pb push_back
#define mp make_pair
#define fi first
#define ld long double
#define se second
using namespace std;
int maxn=0,b[200005];
vector <int> my[200005];
set<int> me[200005];
bool used[200005];
void dfs(int x,int p)
{
    used[x]=1;
    for (int i=1;i<=max(me[p].size(),me[x].size())+1;i++)
    {
        if (me[x].end()==me[x].find(i) && me[p].end()==me[p].find(i)){me[x].insert(i);b[x]=i;break;}
    }
    maxn=max(b[x],maxn);
    for (int j=0;j<my[x].size();j++)
    {
        int v=my[x][j];
        me[v].insert(b[x]);
        if (!used[v]){dfs(v,x);}
    }
}
int main()
{
    int n;
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        my[x].pb(y);
        my[y].pb(x);
    }
    dfs(1,0);
    cout<<maxn<<endl;
    for (int i=1;i<=n;i++)
    cout<<b[i]<<" ";
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n);
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1].pb(b-1);
    gp[b-1].pb(a-1);
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
    int a=st.top();
    st.pop();
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<gp[a].size();i++)
    {
        if(clrs[gp[a][i]]!=0)
        {
            y[clrs[i]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]==0)
        {
            clrs[i]=q.front();
           q.pop();
            st.push(i);
        }
    }
}
int ans=0;
for(int i=0;i<n;i++)
{
    ans=max(ans,clrs[i]);
   // cout<<clrs[i]<<" ";
}
cout<<ans<<endl;
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
void B()
{

}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
A();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n);
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1].pb(b-1);
    gp[b-1].pb(a-1);
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
   // prn1(st.size());
    int a=st.top();
    st.pop();
   // prn1(st.size());
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<gp[a].size();i++)
    {
        if(clrs[gp[a][i]]!=0)
        {
            y[clrs[gp[a][i]]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
          //  prn1(i);
        }
    }
   // cout<<"her";
    for(int i=0;i<gp[a].size();i++)
    {
       // prn2(a,gp[a].size());
        if(clrs[gp[a][i]]==0)
        {
            clrs[gp[a][i]]=q.front();
            //prn3(gp[a][i],q.front(),clrs[gp[a][i]]);
           q.pop();
            st.push(gp[a][i]);
        }
    }
   // cout<<a<<" "<<st.size()<<endl;
}
int ans=0;
for(int i=0;i<n;i++)
{
    ans=max(ans,clrs[i]);
   // cout<<clrs[i]<<" ";
}
cout<<ans<<endl;
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
vi aa[201010];
int n;
int mn=0;
int clr[201010];
vi vis(201010,0);

void dfs(int u, int c,int p)
{
	vis[u] = 1;

	clr[u] = c;
	int k = 1;
	for(int v: aa[u])
	{
		if (!vis[v])
		{
			while (k == c || k == p) ++k;
			dfs(v, k, c);
			++k;
		}
	}
}
void B()
{
   cin>>n;
   int u,v;
   for(int i=0;i<n-1;i++)
   {
       cin >> u >> v;
		aa[u].pb(v);
		aa[v].pb(u);
   }
   for(int i=0;i<n;i++)
	{
		mn = max(mn, sz(aa[i]) + 1);
	}
	cout << mn << endl;

    dfs(1,1,-1);
	for(int i=0;i<n;i++)
		cout << clr[i] << " ";
}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
B();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n);
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1].pb(b-1);
    gp[b-1].pb(a-1);
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
   // prn1(st.size());
    int a=st.top();
    st.pop();
   // prn1(st.size());
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<gp[a].size();i++)
    {
        if(clrs[gp[a][i]]!=0)
        {
            y[clrs[gp[a][i]]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
          //  prn1(i);
        }
    }
   // cout<<"her";
    for(int i=0;i<gp[a].size();i++)
    {
       // prn2(a,gp[a].size());
        if(clrs[gp[a][i]]==0)
        {
            clrs[gp[a][i]]=q.front();
            //prn3(gp[a][i],q.front(),clrs[gp[a][i]]);
           q.pop();
            st.push(gp[a][i]);
        }
    }
   // cout<<a<<" "<<st.size()<<endl;
}
int ans=0;
for(int i=0;i<n;i++)
{
    ans=max(ans,clrs[i]);
   // cout<<clrs[i]<<" ";
}
cout<<ans<<endl;
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
vi aa[201010];
int n;
int mn=0;
int clr[201010];
vi vis(201010,0);

void dfs(int u, int c,int p)
{
	vis[u] = 1;

	clr[u] = c;
	int k = 1;
	for(int v: aa[u])
	{
		if (!vis[v])
		{
			while (k == c || k == p) ++k;
			dfs(v, k, c);
			++k;
		}
	}
}
void B()
{
   cin>>n;
   int u,v;
   for(int i=0;i<n-1;i++)
   {
       cin >> u >> v;
		aa[u].pb(v);
		aa[v].pb(u);
   }
   for(int i=1;i<=n;i++)
	{
		mn = max(mn,(int) sz(aa[i]) + 1);
	}
	cout << mn << endl;

    dfs(1,1,-1);
	for(int i=1;i<=n;i++)
		cout << clr[i] << " ";
}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
B();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n);
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1].pb(b-1);
    gp[b-1].pb(a-1);
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
   // prn1(st.size());
    int a=st.top();
    st.pop();
   // prn1(st.size());
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<gp[a].size();i++)
    {
        if(clrs[gp[a][i]]!=0)
        {
            y[clrs[gp[a][i]]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
          //  prn1(i);
        }
    }
   // cout<<"her";
    for(int i=0;i<gp[a].size();i++)
    {
       // prn2(a,gp[a].size());
        if(clrs[gp[a][i]]==0)
        {
            clrs[gp[a][i]]=q.front();
            //prn3(gp[a][i],q.front(),clrs[gp[a][i]]);
           q.pop();
            st.push(gp[a][i]);
        }
    }
   // cout<<a<<" "<<st.size()<<endl;
}
int ans=0;
for(int i=0;i<n;i++)
{
    ans=max(ans,clrs[i]);
   // cout<<clrs[i]<<" ";
}
cout<<ans<<endl;
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
void B()
{

}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
A();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n,vi(n,0));
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1][b-1]=1;
    gp[b-1][a-1]=1;
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
    int a=st.top();
    st.pop();
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]!=0)
        {
            y[clrs[i]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]==0)
        {
            clrs[i]=q.front();
           q.pop();
            st.push(i);
        }
    }
}
mpii chec;
int ans=0;
for(int i=0;i<n;i++)
{
    if(chec[clrs[i]]==0)
    {
        ans++;
        chec[clrs[i]]=1;
    }
   // cout<<clrs[i]<<" ";
}
cout<<ans<<endl;
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
void B()
{

}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
A();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n,vi(n,0));
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1][b-1]=1;
    gp[b-1][a-1]=1;
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
    int a=st.top();
    st.pop();
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]!=0)
        {
            y[clrs[i]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]==0)
        {
            clrs[i]=q.front();
           q.pop();
            st.push(i);
        }
    }
}
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
void B()
{

}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
A();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef map<int,int> mpii;
typedef map<int,vi> mpivi;
typedef map<string,int> mps;
typedef map<pii,int> map_pair;
typedef set<int> seti;
#define	bits(n)						( (n==0)?0:((int)log2(n)+1) )
#define endl '\n'
#define FOR(i,n) SFOR(i,0,n)
#define SFOR(i,m,n) for(i=m;i<n;i++)
#define FORD(i,n) for(i=n-1;i>=0;i--)
#define digits(i)   (int)((log(i)/log(10))+1)
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) s.size()
#define si(t) scanf("%d",&(t))
#define sll(t) scanf("%lld",&(t))
#define prn1(x)                cout<<#x<<": "<<x<<endl
#define prn2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define prn3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define prn4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define prn5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define prn6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N = 1e5;
const double eps=1e-9;
class myfun
{
    public:
bool operator()(pair<int,pair<int,int> >  a,pair<int,pair<int,int> >  b)
{
    return a.second.second-a.second.first<=b.second.second-b.second.first;
}
};
void A()
{
  //  cout<<"yo"<<endl;
int n;
cin>>n;
vvi gp(n,vi(n,0));
//cout<<"tiy"<<endl;
for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;
    gp[a-1][b-1]=1;
    gp[b-1][a-1]=1;
   // prn2(a,b);
}
//prn1("df");
vi clrs(n,0);
stack<int> st;
st.push(0);
clrs[0]=1;
while(!st.empty())
{
    int a=st.top();
    st.pop();
    mpii y;
    y[clrs[a]]=1;
    queue<int> q;
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]!=0)
        {
            y[clrs[i]]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(y[i]==0)
        {
            q.push(i);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(gp[a][i]==1&&clrs[i]==0)
        {
            clrs[i]=q.front();
           q.pop();
            st.push(i);
        }
    }
}
int ans=0;
for(int i=0;i<n;i++)
{
    ans=max(ans,clrs[i]);
   // cout<<clrs[i]<<" ";
}
cout<<ans<<endl;
for(int i=0;i<n;i++)
{
    cout<<clrs[i]<<" ";
}
}
void B()
{

}

void C()
{
    int t;
    cin>>t;
    for(int l=0;l<t;l++)
    {

    }
}
void D()
{
    string a,b;
    cin>>a>>b;
    map<char,int> mp;
    vi se(a.size());
    for(int i=0;i<a.size();i++)
    {
        cin>>se[i];
        mp[a[i]]++;
    }
    for(int i=0;i<b.size();i++)
    {
        mp[b[i]]--;
    }
    for(int i=0;i<a.size();i++)
    {
        int t=se[i]-1;
        prn3(t,a[t],mp[a[t]]);
        if(mp[a[t]]==0)
        {
            cout<<i<<endl;
        }
        else
        {
            mp[a[t]]--;
        }
    }
}
int main() {
    boost;
    //clock_t t;
   // t=clock();
//freopen("C:\\Users\\asderfers\\Desktop\\in.txt", "r", stdin);
//freopen("C:\\Users\\asderfers\\Desktop\\out.txt", "w", stdout);
    //freopen("J.txt", "r", stdin);
A();
//t = clock() - t;
//  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}


/*=================================*\

      Md. Shahidul Islam
         CSE, BRUR
      Rangpur, Bangladesh
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com
\*=================================*/
#include<bits/stdc++.h>
using namespace std;

#define ll       long long
#define ull      unsinged long long
#define vi       vector<int>
#define vll      vector<ll>
#define ii       pair<int, int>
#define vii      vector<pair<int, int> >
#define vs       vector<string>
#define vd       vector<double>
#define mii       map<int, int>
#define mli       map<ll, int>
#define msi       map<string, int>

#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define rep0(i, k)      for(int i=0;i<k;i++)
#define rep1(i, k)      for(int i=1;i<=k;i++)
#define repab(i, a, b)  for(int i=a;i<=b;i++)
#define repba(i, b, a)  for(int i=b;i>=a;i--)
#define pi              acos(-1.0)
#define eps             1e-6
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9
#define N             200005
bool vis[N];
int col[N];
vi g[N];
void dfs(int u, int rt)
{
    vis[u] = 1;
    //cout << u << " -> " << rt << "\n";
    int s = g[u].size();
    int id = 1;
    if(rt==id)
        id++;
    if(col[u]==id)
        id++;
    rep0(i, s)
    {
        int v = g[u][i];
        if(!vis[v])
        {
            if(rt==id || id==col[u])
                id++;
            col[v] = id++;
            dfs(v, col[u]);
        }
    }
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, u, v, k=0;
    cin>>n;
    rep0(i, n-1)
    {
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
        k = max(k, (int)g[u].size());
        k = max(k, (int)g[v].size());
    }
    col[1] = 1;
    dfs(1, 0);
    cout << k+1 << "\n";
    rep1(i, n)
        cout << col[i] << " ";
    return 0;
}


/*=================================*\

      Md. Shahidul Islam
         CSE, BRUR
      Rangpur, Bangladesh
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com
\*=================================*/
#include<bits/stdc++.h>
using namespace std;

#define ll       long long
#define ull      unsinged long long
#define vi       vector<int>
#define vll      vector<ll>
#define ii       pair<int, int>
#define vii      vector<pair<int, int> >
#define vs       vector<string>
#define vd       vector<double>
#define mii       map<int, int>
#define mli       map<ll, int>
#define msi       map<string, int>

#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define rep0(i, k)      for(int i=0;i<k;i++)
#define rep1(i, k)      for(int i=1;i<=k;i++)
#define repab(i, a, b)  for(int i=a;i<=b;i++)
#define repba(i, b, a)  for(int i=b;i>=a;i--)
#define pi              acos(-1.0)
#define eps             1e-6
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9
#define N             200005
bool vis[N];
int col[N];
vi g[N];
void dfs(int u, int rt)
{
    vis[u] = 1;
    //cout << u << " -> " << rt << "\n";
    int s = g[u].size();
    int id = 1;

    rep0(i, s)
    {
        int v = g[u][i];
        if(!vis[v])
        {
            if(rt==id)
                id++;
            if(col[u]==id)
                id++;
            col[v] = id++;
            dfs(v, col[u]);
        }
    }
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, u, v, k;
    while(cin>>n)
    {
        mem(vis, 0);
        k = 1;
        rep0(i, n-1)
        {
            cin>>u>>v;
            g[u].pb(v);
            g[v].pb(u);
            k = max(k, (int)g[u].size());
            k = max(k, (int)g[v].size());
        }
        col[1] = 1;
        dfs(1, 0);
        cout << k+1 << "\n";
        rep1(i, n)
            cout << col[i] << " ";
        cout << "\n";
        rep0(i, n+1)
            g[i].clear();
    }
    return 0;
}


/*=================================*\

      Md. Shahidul Islam
         CSE, BRUR
      Rangpur, Bangladesh
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com
\*=================================*/
#include<bits/stdc++.h>
using namespace std;

#define ll       long long
#define ull      unsinged long long
#define vi       vector<int>
#define vll      vector<ll>
#define ii       pair<int, int>
#define vii      vector<pair<int, int> >
#define vs       vector<string>
#define vd       vector<double>
#define mii       map<int, int>
#define mli       map<ll, int>
#define msi       map<string, int>

#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define rep0(i, k)      for(int i=0;i<k;i++)
#define rep1(i, k)      for(int i=1;i<=k;i++)
#define repab(i, a, b)  for(int i=a;i<=b;i++)
#define repba(i, b, a)  for(int i=b;i>=a;i--)
#define pi              acos(-1.0)
#define eps             1e-6
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9
#define N             200005
bool vis[N];
int col[N];
vi g[N];
int k;
void dfs(int u, int rt)
{
    vis[u] = 1;
    //cout << u << " -> " << rt << "\n";
    int s = g[u].size();
    int id = 1;
    rep0(i, s)
    {
        int v = g[u][i];
        if(!vis[v])
        {
            if(rt==id)
                id++;
            if(col[u]==id)
                id++;
            col[v] = id++;
            dfs(v, col[u]);
        }
    }
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, u, v, k;
    while(cin>>n)
    {
        mem(vis, 0);
        rep1(i, n-1)
        {
            cin>>u>>v;
            g[u].pb(v);
            g[v].pb(u);
        }
        col[1] = 1;
        dfs(1, 0);
        k = 1;
        rep1(i, n)
            k = max(k, col[i]);
        cout << k << "\n";
        rep1(i, n)
            cout << col[i] << " ";
        cout << "\n";
        rep1(i, n)
            g[i].clear();
    }
    return 0;
}


/*=================================*\

      Md. Shahidul Islam
         CSE, BRUR
      Rangpur, Bangladesh
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com
\*=================================*/
#include<bits/stdc++.h>
using namespace std;

#define ll       long long
#define ull      unsinged long long
#define vi       vector<int>
#define vll      vector<ll>
#define ii       pair<int, int>
#define vii      vector<pair<int, int> >
#define vs       vector<string>
#define vd       vector<double>
#define mii       map<int, int>
#define mli       map<ll, int>
#define msi       map<string, int>

#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define rep0(i, k)      for(int i=0;i<k;i++)
#define rep1(i, k)      for(int i=1;i<=k;i++)
#define repab(i, a, b)  for(int i=a;i<=b;i++)
#define repba(i, b, a)  for(int i=b;i>=a;i--)
#define pi              acos(-1.0)
#define eps             1e-6
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9
#define N             200005
bool vis[N];
int col[N];
vi g[N];
void dfs(int u, int rt)
{
    vis[u] = 1;
    //cout << u << " -> " << rt << "\n";
    int s = g[u].size();
    int id = 1;
    rep0(i, s)
    {
        int v = g[u][i];
        if(!vis[v])
        {
            if(rt==id)
                id++;
            if(col[u]==id)
                id++;
            col[v] = id++;
        }
    }
    rep0(i, s)
    {
        int v = g[u][i];
        if(!vis[v])
        {
            dfs(v, col[u]);
        }
    }
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, u, v, k;
    while(cin>>n)
    {
        mem(vis, 0);
        k = 1;
        rep1(i, n-1)
        {
            cin>>u>>v;
            g[u].pb(v);
            g[v].pb(u);
            k = max(k, (int)g[u].size());
            k = max(k, (int)g[v].size());
        }
        col[1] = 1;
        dfs(1, 0);
        cout << k+1 << "\n";
        rep1(i, n)
            cout << col[i] << " ";
        cout << "\n";
        rep1(i, n)
            g[i].clear();
    }
    return 0;
}


/*=================================*\

      Md. Shahidul Islam
         CSE, BRUR
      Rangpur, Bangladesh
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com
\*=================================*/
#include<bits/stdc++.h>
using namespace std;

#define ll       long long
#define ull      unsinged long long
#define vi       vector<int>
#define vll      vector<ll>
#define ii       pair<int, int>
#define vii      vector<pair<int, int> >
#define vs       vector<string>
#define vd       vector<double>
#define mii       map<int, int>
#define mli       map<ll, int>
#define msi       map<string, int>

#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define sz              size()
#define all(a)          a.begin(), a.end()
#define rep0(i, k)      for(int i=0;i<k;i++)
#define rep1(i, k)      for(int i=1;i<=k;i++)
#define repab(i, a, b)  for(int i=a;i<=b;i++)
#define repba(i, b, a)  for(int i=b;i>=a;i--)
#define pi              acos(-1.0)
#define eps             1e-6
#define mem(a, b)       memset(a, b, sizeof(a))
#define mod             1000000007
#define inf             1e9
#define N             200005
bool vis[N];
int col[N];
vi g[N];
void dfs(int u, int rt)
{
    vis[u] = 1;
    //cout << u << " -> " << rt << "\n";
    int s = g[u].size();
    int id = 1;
    rep0(i, s)
    {
        int v = g[u][i];
        if(!vis[v])
        {
            if(rt==id || col[u]==id)
                id++;
            if(rt==id || col[u]==id)
                id++;
            col[v] = id++;
            dfs(v, col[u]);
        }
    }
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, u, v, k;
    while(cin>>n)
    {
        mem(vis, 0);
        k = 1;
        rep1(i, n-1)
        {
            cin>>u>>v;
            g[u].pb(v);
            g[v].pb(u);
            k = max(k, (int)g[u].size());
            k = max(k, (int)g[v].size());
        }
        col[1] = 1;
        dfs(1, 0);
        cout << k+1 << "\n";
        rep1(i, n)
            cout << col[i] << " ";
        cout << "\n";
        rep1(i, n)
            g[i].clear();
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define _DEBUG

using namespace std;

typedef struct node_s {
    int parent;
    int color;
    vector<int> child;

}node;

node arr[200001];
int n;
bool visited[200001] = {false,};

int max_n = -1;

void solve(int idx) {

    if (visited[idx])
        return;

    visited[idx] = true;

    int used[200001] = {0,};
    if (arr[idx].parent != -1)
        used[arr[idx].parent] = 1;

    used[arr[idx].color] = 1;
    for (int i = 0; i < arr[idx].child.size(); i++) {

        int child = arr[idx].child[i];
        if (arr[child].color != -1)
            continue;

        arr[child].parent = arr[idx].color;
        int j = 1;
        for (; j <= n; j++) {
            if (used[j] == 0) {
                used[j] = 1;
                arr[child].color = j;
                if (j > max_n)
                    max_n = j;
                break;
            }
        }
        solve(child);
    }

}

int main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        arr[i].child = vector<int>();
        arr[i].color = -1;
        arr[i].parent = -1;
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        arr[a].child.push_back(b);
        arr[b].child.push_back(a);
    }

    arr[1].color = 1;
    arr[1].parent = -1;
    solve(1);
    cout << max_n << endl;
    for (int i = 1; i <= n; i++) {
        cout << arr[i].color << " ";
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define _DEBUG

using namespace std;

typedef struct node_s {
    int parent;
    int color;
    vector<int> child;

}node;

node arr[200001];
int n;
bool visited[200001] = {false,};

void solve(int idx) {

    if (visited[idx])
        return;

    visited[idx] = true;

    int used[200001] = {0,};
    if (arr[idx].parent != -1)
        used[arr[idx].parent] = 1;

    used[arr[idx].color] = 1;
    for (int i = 0; i < arr[idx].child.size(); i++) {

        int child = arr[idx].child[i];
        if (arr[child].color != -1)
            continue;

        arr[child].parent = arr[idx].color;
        int j = 1;
        for (; j <= n; j++) {
            if (used[j] == 0) {
                used[j] = 1;
                arr[child].color = j;
                break;
            }
        }
        solve(child);
    }

}

int main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        arr[i].child = vector<int>();
        arr[i].color = -1;
        arr[i].parent = -1;
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        arr[a].child.push_back(b);
        arr[b].child.push_back(a);
    }

    arr[1].color = 1;
    arr[1].parent = -1;
    solve(1);

    for (int i = 1; i <= n; i++) {
        cout << arr[i].color << " ";
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define _DEBUG

using namespace std;

typedef struct node_s {
    int parent;
    int color;
    vector<int> child;

}node;

node arr[200001];
int n;
bool visited[200001] = {false,};

int max_n = -1;

void solve(int idx) {

    if (visited[idx])
        return;

    visited[idx] = true;

    int child_col = 1;
    for (int i = 0; i < arr[idx].child.size(); i++) {

        int child = arr[idx].child[i];
        if (arr[child].color != -1)
            continue;

        arr[child].parent = arr[idx].color;

        while (child_col == arr[idx].color || child_col == arr[idx].parent)
            child_col++;

        arr[child].color = child_col;
        child_col++;
        solve(child);
    }

}

int main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        arr[i].child = vector<int>();
        arr[i].color = -1;
        arr[i].parent = -1;
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        arr[a].child.push_back(b);
        arr[b].child.push_back(a);
    }

    arr[1].color = 1;
    arr[1].parent = -1;
    solve(1);

    for (int i = 1; i <= n; i++) {
        if (max_n < arr[i].color)
            max_n = arr[i].color;
    }
    cout << max_n << endl;

    for (int i = 1; i <= n; i++) {
        cout << arr[i].color << " ";
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define _DEBUG

using namespace std;

typedef struct node_s {
    int parent;
    int color;
    vector<int> child;

}node;

node arr[200001];
int n;
bool visited[200001] = {false,};

int max_n = -1;

void solve(int idx) {

    if (visited[idx])
        return;

    visited[idx] = true;

    bool used[200001] = {false,};
    if (arr[idx].parent != -1)
        used[arr[idx].parent] = true;

    used[arr[idx].color] = true;
    int child_col = 1;
    for (int i = 0; i < arr[idx].child.size(); i++) {

        int child = arr[idx].child[i];
        if (arr[child].color != -1)
            continue;

        arr[child].parent = arr[idx].color;

        while (used[child_col])
            child_col++;

        used[child_col] = true;
        arr[child].color = child_col;
        solve(child);
    }

}

int main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        arr[i].child = vector<int>();
        arr[i].color = -1;
        arr[i].parent = -1;
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        arr[a].child.push_back(b);
        arr[b].child.push_back(a);
    }

    arr[1].color = 1;
    arr[1].parent = -1;
    solve(1);

    for (int i = 1; i <= n; i++) {
        if (max_n < arr[i].color)
            max_n = arr[i].color;
    }
    cout << max_n << endl;

    for (int i = 1; i <= n; i++) {
        cout << arr[i].color << " ";
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#define _DEBUG

using namespace std;

typedef struct node_s {
    int parent;
    int color;
    vector<int> child;

}node;

node arr[200001];
int n;
bool visited[200001] = {false,};

int max_n = -1;

void solve(int idx) {

    if (visited[idx])
        return;

    visited[idx] = true;

    int child_col = 1;
    for (int i = 0; i < arr[idx].child.size(); i++) {

        int child = arr[idx].child[i];
        if (arr[child].color != -1)
            continue;

        arr[child].parent = arr[idx].color;

        while (child_col == arr[idx].color || child_col == arr[idx].parent)
            child_col++;

        arr[child].color = child_col;
        solve(child);
    }

}

int main() {

    cin >> n;

    for (int i = 1; i <= n; i++) {
        arr[i].child = vector<int>();
        arr[i].color = -1;
        arr[i].parent = -1;
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        arr[a].child.push_back(b);
        arr[b].child.push_back(a);
    }

    arr[1].color = 1;
    arr[1].parent = -1;
    solve(1);

    for (int i = 1; i <= n; i++) {
        if (max_n < arr[i].color)
            max_n = arr[i].color;
    }
    cout << max_n << endl;

    for (int i = 1; i <= n; i++) {
        cout << arr[i].color << " ";
    }

    return 0;
}


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

vector<int> l[100009];
set<int> s;
int vis[100009],val[100009],ans,cnt,don[100009];

void dfs(int ver){
	int i,j,t1,t2,c1,c2,c3,k;
	vis[ver]=1;
	//printf("y=%d %d\n",ver,cnt);
	s.clear();
	if(val[ver]==-1){
		for(k=1;k<=cnt;k++){
			if(s.find(k)==s.end()){
				s.insert(k);
				val[ver]=k;
				break;
			}
		}
		if(val[ver]==-1){
			s.insert(++cnt);
			val[ver]=cnt;
		}
	}
	else
	    s.insert(val[ver]);
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(val[t1]!=-1 && vis[t1]==-1){
			s.insert(val[t1]);
		}
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		//printf("y=%d\n",t1);
		if(vis[t1]==-1 && l[t1].size()>1){
			//printf("y=%d %d\n",t1,cnt);
			if(val[t1]==-1){
				for(k=1;k<=cnt;k++){
					if(s.find(k)==s.end()){
						s.insert(k);
						val[t1]=k;
						break;
					}
				}
				if(val[t1]==-1){
					s.insert(++cnt);
					val[t1]=cnt;
				}
			}
			else
			    s.insert(val[t1]);
			for(j=0;j<l[t1].size();j++){
				t2=l[t1][j];
				if(val[t2]==-1){
					for(k=1;k<=cnt;k++){
						if(s.find(k)==s.end()){
							s.insert(k);
							val[t2]=k;
							break;
						}
					}
					if(val[t2]==-1){
						s.insert(++cnt);
						val[t2]=cnt;
					}
				}
				else
				    s.insert(val[t2]);
			}
		}
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==-1 && l[t1].size()>1)
			dfs(t1);
	}
}

int main() {
	int i,j,t1,t2,t3,t4,x,y,n;
	scanf("%d",&n);
	for(i=0;i<n-1;i++){
		scanf("%d %d",&x,&y);
		l[x].push_back(y);
		l[y].push_back(x);
	}
	memset(vis,-1,sizeof(vis));
	memset(val,-1,sizeof(val));
	ans=0;
	cnt=1;
	s.clear();
	dfs(1);
	printf("%d\n",cnt);
	for(i=1;i<=n;i++){
		printf("%d ",val[i]);
	}
	printf("\n");
	return 0;
}


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

vector<int> l[100009];
set<int> s;
int vis[100009],val[100009],ans,cnt,don[100009];

void dfs(int ver){
	int i,j,t1,t2,c1,c2,c3,k;
	vis[ver]=1;
	if(val[ver]==-1){
		for(k=1;k<=cnt;k++){
			if(s.find(k)==s.end()){
				s.insert(k);
				val[ver]=k;
				break;
			}
		}
		if(val[ver]==-1){
			s.insert(++cnt);
			val[ver]=cnt;
		}
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==-1){
			if(val[t1]==-1){
				for(k=1;k<=cnt;k++){
					if(s.find(k)==s.end()){
						s.insert(k);
						val[t1]=k;
						break;
					}
				}
				if(val[t1]==-1){
					s.insert(++cnt);
					val[t1]=cnt;
				}
			}
			for(j=0;j<l[t1].size();j++){
				t2=l[t1][j];
				if(val[t2]==-1){
					for(k=1;k<=cnt;k++){
						if(s.find(k)==s.end()){
							s.insert(k);
							val[t2]=k;
							break;
						}
					}
					if(val[t2]==-1){
						s.insert(++cnt);
						val[t2]=cnt;
					}
				}
			}
			c1=l[t1].size()-1+2;
			ans=max(ans,c1);
			s.erase(val[ver]);
			dfs(t1);
		}
	}
}

int main() {
	int i,j,t1,t2,t3,t4,x,y,n;
	scanf("%d",&n);
	for(i=0;i<n-1;i++){
		scanf("%d %d",&x,&y);
		l[x].push_back(y);
		l[y].push_back(x);
	}
	memset(vis,-1,sizeof(vis));
	memset(val,-1,sizeof(val));
	ans=0;
	cnt=1;
	s.clear();
	dfs(1);
	printf("%d\n",ans);
	for(i=1;i<=n;i++){
		printf("%d ",val[i]);
	}
	printf("\n");
	return 0;
}


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

vector<int> l[200009];
set<int> s;
int vis[200009],cnt,val[200009];

void dfs(int ver){
	int i,j,t1,t2;
	vis[ver]=1;
	s.clear();
	s.insert(val[ver]);
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==1)
			s.insert(val[t1]);
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==-1){
			for(j=1;j<=cnt;j++){
				if(s.find(j)==s.end()){
					val[t1]=j;
					s.insert(j);
					break;
				}
			}
			if(val[t1]==-1){
				val[t1]=++cnt;
				s.insert(val[t1]);
			}
			//dfs(t1);
		}
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==-1)
			dfs(t1);
	}
}

int main() {
	int i,j,t1,t2,t3,t4,ans,n;
	scanf("%d",&n);
	for(i=0;i<n-1;i++){
		scanf("%d %d",&t1,&t2);
		l[t1].push_back(t2);
		l[t2].push_back(t1);
	}
	memset(vis,-1,sizeof(vis));
	memset(val,-1,sizeof(val));
	cnt=1;
	val[1]=1;
	dfs(1);
	printf("%d\n",cnt);
	for(i=1;i<=n;i++){
		printf("%d ",val[i]);
	}
	printf("\n");
	return 0;
}


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

vector<int> l[200009];
set<int> s;
int vis[200009],cnt,val[200009];

void dfs(int ver){
	int i,j,t1,t2,temp;
	vis[ver]=1;
	s.clear();
	s.insert(val[ver]);
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==1)
			s.insert(val[t1]);
	}
	temp=1;
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==-1){
			while(s.find(temp)!=s.end())
				temp++;
			cnt=max(temp,cnt);
			val[t1]=temp;
			s.insert(temp);
			//dfs(t1);
		}
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(vis[t1]==-1)
			dfs(t1);
	}
}

int main() {
	int i,j,t1,t2,t3,t4,ans,n;
	scanf("%d",&n);
	for(i=0;i<n-1;i++){
		scanf("%d %d",&t1,&t2);
		l[t1].push_back(t2);
		l[t2].push_back(t1);
	}
	memset(vis,-1,sizeof(vis));
	memset(val,-1,sizeof(val));
	cnt=1;
	val[1]=1;
	dfs(1);
	printf("%d\n",cnt);
	for(i=1;i<=n;i++){
		printf("%d ",val[i]);
	}
	printf("\n");
	return 0;
}


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

vector<int> l[100009];
set<int> s;
int vis[100009],val[100009],ans,cnt,don[100009];

void dfs(int ver){
	int i,j,t1,t2,c1,c2,c3,k;
	vis[ver]=1;
	s.clear();
	if(val[ver]==-1){
		for(k=1;k<=cnt;k++){
			if(s.find(k)==s.end()){
				s.insert(k);
				val[ver]=k;
				break;
			}
		}
		if(val[ver]==-1){
			s.insert(++cnt);
			val[ver]=cnt;
		}
	}
	else
	    s.insert(val[ver]);
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		if(val[t1]!=-1){
			s.insert(val[t1]);
		}
	}
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		//printf("y=%d\n",t1);
		if(vis[t1]==-1 && l[t1].size()>0){
			//printf("y=%d %d\n",t1,cnt);
			if(val[t1]==-1){
				for(k=1;k<=cnt;k++){
					if(s.find(k)==s.end()){
						s.insert(k);
						val[t1]=k;
						break;
					}
				}
				if(val[t1]==-1){
					s.insert(++cnt);
					val[t1]=cnt;
				}
			}
			else
			    s.insert(val[t1]);
			for(j=0;j<l[t1].size();j++){
				t2=l[t1][j];
				if(val[t2]==-1){
					for(k=1;k<=cnt;k++){
						if(s.find(k)==s.end()){
							s.insert(k);
							val[t2]=k;
							break;
						}
					}
					if(val[t2]==-1){
						s.insert(++cnt);
						val[t2]=cnt;
					}
				}
				else
				    s.insert(val[t2]);
			}
		}
		}
		//s.erase(val[ver]);
		for(i=0;i<l[ver].size();i++){
			t1=l[ver][i];
			if(vis[t1]==-1 && l[t1].size()>0)
				dfs(t1);
		}
}

int main() {
	int i,j,t1,t2,t3,t4,x,y,n;
	scanf("%d",&n);
	for(i=0;i<n-1;i++){
		scanf("%d %d",&x,&y);
		l[x].push_back(y);
		l[y].push_back(x);
	}
	memset(vis,-1,sizeof(vis));
	memset(val,-1,sizeof(val));
	ans=0;
	cnt=1;
	s.clear();
	dfs(1);
	printf("%d\n",cnt);
	for(i=1;i<=n;i++){
		printf("%d ",val[i]);
	}
	printf("\n");
	return 0;
}


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

vector<int> l[100009];
set<int> s;
int vis[100009],val[100009],ans,cnt,don[100009];

void dfs(int ver){
	int i,j,t1,t2,c1,c2,c3,k;
	vis[ver]=1;
	s.clear();
	if(val[ver]==-1){
		for(k=1;k<=cnt;k++){
			if(s.find(k)==s.end()){
				s.insert(k);
				val[ver]=k;
				break;
			}
		}
		if(val[ver]==-1){
			s.insert(++cnt);
			val[ver]=cnt;
		}
	}
	else
	    s.insert(val[ver]);
	for(i=0;i<l[ver].size();i++){
		t1=l[ver][i];
		//printf("y=%d\n",t1);
		if(vis[t1]==-1 && l[t1].size()>0){
			//printf("y=%d %d\n",t1,cnt);
			if(val[t1]==-1){
				for(k=1;k<=cnt;k++){
					if(s.find(k)==s.end()){
						s.insert(k);
						val[t1]=k;
						break;
					}
				}
				if(val[t1]==-1){
					s.insert(++cnt);
					val[t1]=cnt;
				}
			}
			else
			    s.insert(val[t1]);
			for(j=0;j<l[t1].size();j++){
				t2=l[t1][j];
				if(val[t2]==-1){
					for(k=1;k<=cnt;k++){
						if(s.find(k)==s.end()){
							s.insert(k);
							val[t2]=k;
							break;
						}
					}
					if(val[t2]==-1){
						s.insert(++cnt);
						val[t2]=cnt;
					}
				}
				else
				    s.insert(val[t2]);
			}
		}
		}
		//s.erase(val[ver]);
		for(i=0;i<l[ver].size();i++){
			t1=l[ver][i];
			if(vis[t1]==-1 && l[t1].size()>0)
				dfs(t1);
		}
}

int main() {
	int i,j,t1,t2,t3,t4,x,y,n;
	scanf("%d",&n);
	for(i=0;i<n-1;i++){
		scanf("%d %d",&x,&y);
		l[x].push_back(y);
		l[y].push_back(x);
	}
	memset(vis,-1,sizeof(vis));
	memset(val,-1,sizeof(val));
	ans=0;
	cnt=1;
	s.clear();
	dfs(1);
	printf("%d\n",cnt);
	for(i=1;i<=n;i++){
		printf("%d ",val[i]);
	}
	printf("\n");
	return 0;
}