stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <climits>

using namespace std;



int N, M;//?度? n 的序列,有 m 个操作

int F[205000];

bool Jud[205000];



int main()

{

    cin >> N >> M;

    memset(Jud, true, sizeof(Jud));

    for(int i = 1; i <= M; i++)    cin >> F[i];

    for(int i = M; i >= 1; i--)

        if(Jud[F[i]] == true){

            Jud[F[i]] = false;

            cout << F[i] << endl;

        }

    for(int i = 1; i <= N; i++)

        if(Jud[i] == true)

            cout << i << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.1780538785331354x):
#include <bits/stdc++.h>



using namespace std;



#define INF 1001000100010001000

#define MOD 1000000007

#define EPS 1e-10

#define int long long

#define rep(i, N) for (int i = 0; i < N; i++)

#define Rep(i, N) for (int i = 1; i < N; i++)

#define For(i, a, b) for (int i = (a); i < (b); i++)

#define pb push_back

#define eb emplace_back

#define mp make_pair

#define i_i pair<int, int>

#define vi vector<int>

#define vvi vector<vi >

#define vb vector<bool>

#define vvb vector<vb >

#define vp vector< i_i >

#define all(a) (a).begin(), (a).end()

#define Int(x) int x; cin >> x;

#define int2(x, y) Int(x); Int(y);

#define int3(x, y, z) Int(x); int2(y, z);

#define fir first

#define sec second

#define ffir first.first

#define fsec first.second

#define sfir second.first

#define ssec second.second

#define Decimal fixed << setprecision(10)



//int dxy[5] = {0, 1, 0, -1, 0};

// cmd



signed main()

{

    std::ios::sync_with_stdio(false);

    std::cin.tie(0);



    int2(n, m);

    vb used(n, false);

    vector<int> data(m);

    for (int i = 0; i < m; i++) {

        cin >> data[i];

        used[data[i]-1] = true;

    }



    vb out(n, false);

    for (int i = m-1; i >= 0; i--) {

        if (!out[data[i]-1]) {

            cout << data[i] << endl;

            out[data[i]-1] = true;

        }

    }



    rep(i, n) {

        if (!used[i]) cout << i+1 << endl;

    }

    



    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int main()

{

	int n,m,a[200001];

	bool b1[200001],b2[200001];

	cin>>n>>m;

	memset(b1,1,sizeof(b1));

	memset(b2,1,sizeof(b2));

	for (int i=1;i<=m;i++){

		cin>>a[i];

		b1[a[i]]=false;

	}

	for(int i=m;i>=1;i--){

		if (b2[a[i]]==true){

			cout<<a[i]<<endl;

			b2[a[i]]=0;

		}

	}

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

		if (b1[i]==true) cout<<i<<endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.4386373240161614x):
#include <algorithm>

#include <iostream>

#include <set>

#include <utility>

using int_t = long long int;

using std::cin;

using std::cout;

using std::endl;

const int_t LARGE = 2e5;

int n, m;

int_t seq[LARGE + 1];

bool visited[LARGE + 1];

struct Pair {

    int_t a, b;

} pairs[LARGE + 1];

int main() {

    scanf("%d%d", &n, &m);



    for (int_t i = 1; i <= n; i++) pairs[i] = Pair{i, i};



    int_t var0 = 0;



    for (int_t i = 1; i <= m; i++) {

        int_t x;

        scanf("%lld", &x);

        pairs[x].b = var0;

        var0 -= 1;

    }

    std::sort(pairs + 1, pairs + 1 + n,

              [](const Pair& a, const Pair& b) -> bool { return a.b < b.b; });

    for (int_t i = 1; i <= n; i++) printf("%lld\n", pairs[i].a);

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<iostream>

#include<memory.h>

using namespace std;

bool vis[200005];

bool vis1[200005];

int a[200005];

int main()

{

    memset(vis,0,sizeof(vis));

    memset(vis1,0,sizeof(vis1));

    int n,m;

    scanf("%d%d",&n,&m);

    int j=0;

    for(int i=0;i<m;i++)

    {

        int b;

        scanf("%d",&b);

        vis[b]=1;

        a[j++]=b;

    }

    while(j--)

    {

        if(vis1[a[j]]==0)

        {

            printf("%d\n",a[j]);

            vis1[a[j]]=1;

        }

    } 

    for(int i=1;i<=n;i++)

    {

        if(vis[i]==0) 

        printf("%d\n",i);

    }

    return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 1.4054155227858223x):
#include <algorithm>

#include <iostream>

#include <set>

#include <utility>

using int_t = long long int;

using std::cin;

using std::cout;

using std::endl;

const int_t LARGE = 2e5;

int n, m;

int_t seq[LARGE + 1];

bool visited[LARGE + 1];

struct Pair {

    int_t a, b;

} pairs[LARGE + 1];

int main() {

    scanf("%d%d", &n, &m);



    for (int_t i = 1; i <= n; i++) pairs[i] = Pair{i, i};



    int_t var0 = 0;



    for (int_t i = 1; i <= m; i++) {

        int_t x;

        scanf("%lld", &x);

        pairs[x].b = var0;

        var0 -= 1;

    }

    std::sort(pairs + 1, pairs + 1 + n,

              [](const Pair& a, const Pair& b) -> bool { return a.b < b.b; });

    for (int_t i = 1; i <= n; i++) printf("%lld\n", pairs[i].a);

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cstdio>

#include <cstring>

#include <algorithm>

#include <climits>

using namespace std;



int N, M;//?度? n 的序列,有 m 个操作

int F[205000];

bool Jud[205000];



int main()

{

    cin >> N >> M;

    memset(Jud, true, sizeof(Jud));

    for(int i = 1; i <= M; i++)    cin >> F[i];

    for(int i = M; i >= 1; i--)

        if(Jud[F[i]] == true){

            Jud[F[i]] = false;

            cout << F[i] << endl;

        }

    for(int i = 1; i <= N; i++)

        if(Jud[i] == true)

            cout << i << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.21551382173427x):
#include <algorithm>

#include <iostream>

#include <set>

#include <utility>

using int_t = long long int;

using std::cin;

using std::cout;

using std::endl;

const int_t LARGE = 2e5;

int n, m;

int_t seq[LARGE + 1];

bool visited[LARGE + 1];

struct Pair {

    int_t a, b;

} pairs[LARGE + 1];

int main() {

    scanf("%d%d", &n, &m);



    for (int_t i = 1; i <= n; i++) pairs[i] = Pair{i, i};



    int_t var0 = 0;



    for (int_t i = 1; i <= m; i++) {

        int_t x;

        scanf("%lld", &x);

        pairs[x].b = var0;

        var0 -= 1;

    }

    std::sort(pairs + 1, pairs + 1 + n,

              [](const Pair& a, const Pair& b) -> bool { return a.b < b.b; });

    for (int_t i = 1; i <= n; i++) printf("%lld\n", pairs[i].a);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



constexpr ll N=100001;

vector <ll> tree[N];

vector <ll> exam (N,0);

map<pair<ll,ll>,ll> I;

vector <pair <ll,ll>> v(N);



ll maxcol=0;

void dfs(pair <int,int> now){

  ll ncol=1;



  for (auto i:tree[now.first]){

    if (exam[i]) continue;

    if (ncol==now.second) ncol++;

    exam[i]=ncol;

    I[make_pair(now.first,i)]=I[make_pair(i,now.first)]=ncol;

    maxcol=max(maxcol,ncol);



    dfs(make_pair(i,ncol));

    ncol++;

  }



}



  int main(){

    ll n;

    cin>>n;

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

      ll a,b;

      cin>>a>>b;

      tree[a].emplace_back(b);

      tree[b].emplace_back(a);

      v[i]=make_pair(a,b);

    }

    exam[1]=N;



    dfs(make_pair(1,0));





    cout<<maxcol<<endl;

    for (ll i=0;i<n-1; i++){

      cout<<I[v[i]]<<endl;

    }



  }


// Faster C++ solution for the same problem (measured speedup: 6.228210767090506x):


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> l_l;

typedef pair<int, int> P;

#define rep(i,n) for(ll i=0;i<n;++i)

const int INF=1001001001;

int main(){

  ll n;

  cin>>n;

  vector<vector<P>> g(n);

  vector<int> cn(n,INF);

  vector<int> ce(n-1,INF);

  rep(i,n-1){

    int a1,b1;

    cin>>a1>>b1;

    a1--;b1--;

    g[a1].push_back(make_pair(b1,i));

    g[b1].push_back(make_pair(a1,i));



  }





queue <int> q;

q.push(0);

int maxc=0;

while (!q.empty()){

  int now=q.front();

  q.pop();

  int cnt=1;



  for(auto to:g[now]){

    int nod=to.first;

    int edg=to.second;



    if (ce[edg]!=INF)continue;

    if (cn[now]==cnt) cnt++;

    ce[edg]=cnt;

    cn[nod]=cnt;

    maxc=max(maxc,cnt);

    q.push(nod);

    cnt++;

  }



}

cout<<maxc<<endl;

rep(i,n-1){

  cout<<ce[i]<<endl;

}













  }
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long int ll;

typedef pair<int, int> P;



int n;

vector<vector<int>> graph(101010, vector<int>(0));

vector<int> colors(101010);

map<P, int> edge_num;

int mc = 0;



void dfs(int a, int pa, int pc){

  int c = 1;

  for(int x : graph.at(a)){

    if(x == pa) continue;

    if(c == pc) c++;

    colors.at(edge_num[P(x, a)]) = c;

    dfs(x, a, c);

    c++;

  }

  mc = max(c - 1, mc);

}



int main(){

  cin >> n;

  rep(i, n - 1){

    int a, b;

    cin >> a >> b;

    graph.at(a).emplace_back(b);

    graph.at(b).emplace_back(a);

    edge_num[P(a, b)] = edge_num[P(b, a)] = i;

  }

  

  dfs(1, 0, 0);

  

  cout << mc << endl;

  rep(i, n - 1) cout << colors[i] << endl;

  

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.9114534900857514x):
#include <bits/stdc++.h>

using namespace std;

#define rep2(i,m,n) for (int i = (m); i < (n); ++i)

#define rep(i,n) rep2(i,0,n)

typedef long long int ll;

typedef long double ld;

typedef pair<int, int> P;

template<typename T> struct V : vector<T> { using vector<T>::vector; };

V() -> V<int>;

V(size_t) -> V<int>;

template<typename T> V(size_t, T) -> V<T>;

template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }

template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }

template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }

struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

const int INF = 1<<30;

const ll LINF = 1LL<<61;



vector<vector<P>> G;

vector<int> ans;



void func(int cur, int p, int c)

{

    int nc = 1;

    for(auto [to, e]:G[cur])

    {

        if(to == p) continue;

        if(nc == c) nc++;

        ans[e] = nc;

        func(to, cur, nc);

        nc++;

    }

    return;

}



int main()

{

    int n;

    cin >> n;

    G.assign(n, vector<P>(0));

    ans.assign(n-1, 0);

    rep(i,n-1)

    {

        int u, v;

        cin >> u >> v;

        --u; --v;

        G[u].emplace_back(v, i);

        G[v].emplace_back(u, i);

    }

    func(0, -1, 0);

    ll ans1 = 0;

    for(auto x:ans) chmax(ans1, x);

    cout << ans1 << endl;

    for(auto x:ans) cout << x << "\n";

    



    return 0;

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

using vvi = vector<vi>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define eb emplace_back

#define NMAX 100000



int K = 1;

vvi tree(NMAX);

vi colors(NMAX), visited(NMAX);



void dfs(int p, int p_color){

	K = max(K, (int)tree[p].size());

	int color = 1;

	for(int c:tree[p]){

		if(visited[c]) continue;

		visited[c] = true;

		colors[c] = color==p_color? ++color: color;

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	vi C(N-1);

	rp(i, 0, N-1){

		int p,c; cin>>p>>c; p--,c--;

		tree[p].eb(c); tree[c].eb(p);

		C[i] = c;

	}

	visited[0] = true;

	dfs(0, -1);

	cout<< K <<endl;

	for(auto c:C) cout<< colors[c] <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.53685690940801x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define rp(i,s,e) for(int i=(s);i<(e);++i)



int main(){

	int N; cin>>N;

	int G[N], C[N-1];

	rp(i, 0, N-1){

		int p; scanf("%d%d", &p, C+i);

		G[--C[i]] = p-1;

	}



	int K = 1;

	int colors[N], pre_colors[N]; rp(i, 0, N) colors[i] = pre_colors[i] = 0;



	rp(c, 1, N){

		int p = G[c];

		int color = pre_colors[p] + 1;

		pre_colors[p] = colors[c] = color==colors[p]? ++color: color;

		K = max(K, color);

	}



	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

using vvi = vector<vi>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define eb emplace_back

#define NMAX 100000



int K = 1;

vvi tree(NMAX);

vi colors(NMAX), visited(NMAX);



void dfs(int p, int p_color){

	K = max(K, (int)tree[p].size());

	int color = 1;

	for(int c:tree[p]){

		if(visited[c]) continue;

		visited[c] = true;

		colors[c] = color==p_color? ++color: color;

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	vi C(N-1);

	rp(i, 0, N-1){

		int p,c; cin>>p>>c; p--,c--;

		tree[p].eb(c); tree[c].eb(p);

		C[i] = c;

	}

	visited[0] = true;

	dfs(0, -1);

	cout<< K <<endl;

	for(auto c:C) cout<< colors[c] <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.481567650193911x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define rp(i,s,e) for(int i=(s);i<(e);++i)



int main(){

	int N; cin>>N;

	vector<vector<int>> tree(N);

	int C[N-1];

	rp(i, 0, N-1){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

		tree[C[i]].push_back(p);

	}



	int K = 0;

	int colors[N], visited[N]; rp(i, 0, N) colors[i] = visited[i] = 0;



	queue<int> q;

	q.push(0);

	visited[0] = true;

	while(!q.empty()){

		int p = q.front(); q.pop();

		int color = 1;

		for(auto c:tree[p]){

			if(visited[c]) continue;

			q.push(c);

			visited[c] = true;

			colors[c] = color==colors[p]? ++color: color;

			K = max(K, color++);

		}

	}



	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

using vvi = vector<vi>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define eb emplace_back

#define NMAX 100000



int K = 1;

vvi tree(NMAX);

vi colors(NMAX), visited(NMAX);



void dfs(int p, int p_color){

	K = max(K, (int)tree[p].size());

	int color = 1;

	for(int c:tree[p]){

		if(visited[c]) continue;

		visited[c] = true;

		colors[c] = color==p_color? ++color: color;

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	vi C(N-1);

	rp(i, 0, N-1){

		int p,c; cin>>p>>c; p--,c--;

		tree[p].eb(c); tree[c].eb(p);

		C[i] = c;

	}

	visited[0] = true;

	dfs(0, -1);

	cout<< K <<endl;

	for(auto c:C) cout<< colors[c] <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.2763731569205325x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define NMAX 100000



int K = 1;

vector<vector<int>> tree(NMAX);

int colors[NMAX];



void dfs(int p, int p_color){

	int color = 1;

	for(int c:tree[p]){

		if(colors[c]) continue;

		colors[c] = color==p_color? ++color: color;

		K = max(K, color);

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	int C[N-1];

	for(int i=0; i<N-1; ++i){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

		tree[C[i]].push_back(p);

	}

	colors[0] = NMAX;

	dfs(0, -1);

	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

using vvi = vector<vi>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define eb emplace_back

#define NMAX 100000



int K = 1;

vvi tree(NMAX);

vi colors(NMAX), visited(NMAX);



void dfs(int p, int p_color){

	K = max(K, (int)tree[p].size());

	int color = 1;

	for(int c:tree[p]){

		if(visited[c]) continue;

		visited[c] = true;

		colors[c] = color==p_color? ++color: color;

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	vi C(N-1);

	rp(i, 0, N-1){

		int p,c; cin>>p>>c; p--,c--;

		tree[p].eb(c); tree[c].eb(p);

		C[i] = c;

	}

	visited[0] = true;

	dfs(0, -1);

	cout<< K <<endl;

	for(auto c:C) cout<< colors[c] <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.2765710675723985x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define NMAX 100000



int K = 1;

vector<vector<int>> tree(NMAX);

int colors[NMAX];



void dfs(int p, int p_color){

	int color = 1;

	for(int c:tree[p]){

		if(colors[c]) continue;

		colors[c] = color==p_color? ++color: color;

		K = max(K, color);

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	int C[N-1];

	for(int i=0; i<N-1; ++i){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

	}

	colors[0] = NMAX;

	dfs(0, -1);

	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

using vvi = vector<vi>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define eb emplace_back

#define NMAX 100000



int K = 1;

vvi tree(NMAX);

vi colors(NMAX), visited(NMAX);



void dfs(int p, int p_color){

	K = max(K, (int)tree[p].size());

	int color = 1;

	for(int c:tree[p]){

		if(visited[c]) continue;

		visited[c] = true;

		colors[c] = color==p_color? ++color: color;

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	vi C(N-1);

	rp(i, 0, N-1){

		int p,c; cin>>p>>c; p--,c--;

		tree[p].eb(c); tree[c].eb(p);

		C[i] = c;

	}

	visited[0] = true;

	dfs(0, -1);

	cout<< K <<endl;

	for(auto c:C) cout<< colors[c] <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.484664707653976x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define rp(i,s,e) for(int i=(s);i<(e);++i)



int main(){

	int N; cin>>N;

	vector<vector<int>> tree(N);

	int C[N-1];

	rp(i, 0, N-1){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

	}



	int K = 0;

	int colors[N]; rp(i, 0, N) colors[i] = 0;



	queue<int> q;

	q.push(0);

	colors[0] = -1;

	while(!q.empty()){

		int p = q.front(); q.pop();

		int color = 1;

		for(auto c:tree[p]){

			if(colors[c]) continue;

			q.push(c);

			colors[c] = color==colors[p]? ++color: color;

			K = max(K, color++);

		}

	}



	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define NMAX 100000



int K = 1;

vector<vector<int>> tree(NMAX);

int colors[NMAX];



void dfs(int p, int p_color){

	int color = 1;

	for(int c:tree[p]){

		if(colors[c]) continue;

		colors[c] = color==p_color? ++color: color;

		K = max(K, color);

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	int C[N-1];

	for(int i=0; i<N-1; ++i){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

		tree[C[i]].push_back(p);

	}

	colors[0] = NMAX;

	dfs(0, -1);

	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}

// Faster C++ solution for the same problem (measured speedup: 3.5135999870711734x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define rp(i,s,e) for(int i=(s);i<(e);++i)



int main(){

	int N; cin>>N;

	vector<vector<int>> tree(N);

	int C[N-1];

	rp(i, 0, N-1){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

	}



	int K = 0;

	int colors[N]; rp(i, 0, N) colors[i] = 0;



	queue<int> q;

	q.push(0);

	colors[0] = -1;

	while(!q.empty()){

		int p = q.front(); q.pop();

		int color = 1;

		for(auto c:tree[p]){

			if(colors[c]) continue;

			q.push(c);

			colors[c] = color==colors[p]? ++color: color;

			K = max(K, color++);

		}

	}



	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define NMAX 100000



int K = 1;

vector<vector<int>> tree(NMAX);

int colors[NMAX];



void dfs(int p, int p_color){

	int color = 1;

	for(int c:tree[p]){

		if(colors[c]) continue;

		colors[c] = color==p_color? ++color: color;

		K = max(K, color);

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	int C[N-1];

	for(int i=0; i<N-1; ++i){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

	}

	colors[0] = NMAX;

	dfs(0, -1);

	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}

// Faster C++ solution for the same problem (measured speedup: 3.513055263098101x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define rp(i,s,e) for(int i=(s);i<(e);++i)



int main(){

	int N; cin>>N;

	vector<vector<int>> tree(N);

	int C[N-1];

	rp(i, 0, N-1){

		int p; scanf("%d%d", &p, C+i); p--,C[i]--;

		tree[p].push_back(C[i]);

	}



	int K = 0;

	int colors[N]; rp(i, 0, N) colors[i] = 0;



	queue<int> q;

	q.push(0);

	colors[0] = -1;

	while(!q.empty()){

		int p = q.front(); q.pop();

		int color = 1;

		for(auto c:tree[p]){

			if(colors[c]) continue;

			q.push(c);

			colors[c] = color==colors[p]? ++color: color;

			K = max(K, color++);

		}

	}



	printf("%d\n", K);

	for(int c:C) printf("%d\n", colors[c]);

}
// Slower C++ solution:
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

using vi = vector<int>;

using vvi = vector<vi>;

#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define eb emplace_back

#define NMAX 100000



int K = 1;

vvi tree(NMAX);

vi colors(NMAX), visited(NMAX);



void dfs(int p, int p_color){

	K = max(K, (int)tree[p].size());

	int color = 1;

	for(int c:tree[p]){

		if(visited[c]) continue;

		visited[c] = true;

		colors[c] = color==p_color? ++color: color;

		dfs(c, color++);

	}

}



int main(){

	int N; cin>>N;

	vi C(N-1);

	rp(i, 0, N-1){

		int p,c; cin>>p>>c; p--,c--;

		tree[p].eb(c); tree[c].eb(p);

		C[i] = c;

	}

	visited[0] = true;

	dfs(0, -1);

	cout<< K <<endl;

	for(auto c:C) cout<< colors[c] <<endl;

}

// Faster C++ solution for the same problem (measured speedup: 4.552403249843853x):
// D - Coloring Edges on Tree

#include <bits/stdc++.h>

using namespace std;

#define rp(i,s,e) for(int i=(s);i<(e);++i)



const int dm = 1 << 20;

char dn[dm], * di = dn;

inline void putint(int x){

	char c[10];

	int d; for(d=0; x; d++, x/=10) c[d] = x%10 + '0';

	for(int i=d-1; i>=0; --i) *di++ = c[i];

	*di++ = '\n';

}



int main(){

	int N; cin>>N;

	int G[N], C[N-1];

	rp(i, 0, N-1){

		int p; scanf("%d%d", &p, C+i);

		G[--C[i]] = p-1;

	}



	int K = 1;

	int pre_colors[N]; rp(i, 0, N) pre_colors[i] = 0;



	rp(c, 1, N){

		int p = G[c];

		int color = pre_colors[p] + 1;

		pre_colors[p] = G[c] = color==G[p]? ++color: color;

		K = max(K, color);

	}



	putint(K);

	for(int c:C) putint(G[c]);

	fwrite(dn, 1, di - dn, stdout);

}