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

const int64_t N = int64_t(1e9);

int main() {
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> g(n);
	int ans = 0;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		g[x].emplace_back(y, i);
		g[y].emplace_back(x, i);
		ans = max(ans, int(g[x].size()));
		ans = max(ans, int(g[y].size()));
	}
	vector<int> a(n);
	function<void(int, int, int)> dfs = [&](int x, int p, int c) {
		int cc = 0;
		for (pair<int, int> q : g[x]) {
			if (q.first == p) {
				continue;
			}
			if (cc == c) {
				cc++;
			}
			a[q.second] = cc;
			dfs(q.first, x, cc);
			cc++;
		}
	};
	dfs(0, -1, -1);
	cout << ans << endl;
	for (int i = 1; i < n; i++) {
		cout << a[i] + 1 << endl;
	}
	return 0;
}