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

long long N, MAX = 0;
static vector<pair<long long, long long> > V[100000];
static long long ANS[100000] = {};

void DFS(long long P, long long Q, long long C) {
	long long NOW = 1;
	for (pair<long long, long long> NP : V[P]) {
		long long To = NP.first, X = NP.second;
		if (To == Q) continue;
		else {
			if (C == NOW) NOW++;
			ANS[X] = NOW;
			DFS(To, P, NOW);
		}
		NOW++;
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		long long A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back({ B, i });
		V[B].push_back({ A, i });
	}
	for (int i = 0; i < N; i++) {
		MAX = max(MAX, (long long)(V[i].size()));
	}
	DFS(0, -1, 0);
	cout << MAX << endl;
	for (int i = 0; i < N - 1; i++) cout << ANS[i] << endl;
}