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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream & operator>>(istream & is, vector<T> & vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

map<int, map<int, int>> m;


struct Edge {
	int to;     // 辺の行き先
	int weight; // 辺の重み
	Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int K;	// color max;

// 木上の探索
// v: 現在探索中の頂点、p: v の親 (v が根のときは -1)
void dfs(const Graph& G, int v, int p, int pcolor) {

	int ncolor = 1;
	
	for (auto nv : G[v]) {
		if (nv.to == p) continue; // nv が親 p だったらダメ

		if (ncolor == pcolor) ncolor++;

		nv.weight = ncolor++;

		m[v][nv.to] = nv.weight;
		m[nv.to][v] = nv.weight;

		dfs(G, nv.to, v, nv.weight); // v は新たに nv の親になります
	}
}

signed main() {


	int N;
	cin >> N;
	vector<int> a(N), b(N);
	Graph G(N);
	rep(i, N - 1) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		G[a[i]].push_back({ b[i],0 });
		G[b[i]].push_back({ a[i],0 });
	}

	int idx;
	K = 0;
	rep(i, N) {
		if (G[i].size() > K) {
			K = G[i].size();
			idx = i;
		}
	}

	int k = 1;
	for (auto& v : G[idx]) {
		v.weight = k++;
		m[idx][v.to] = v.weight;
		m[v.to][idx] = v.weight;
	}

	dfs(G, idx, -1, -1);

	cout << K << endl;
	rep(i, N - 1) {
		cout << m[a[i]][b[i]] << endl;
	}


}

Measured memory_bytes: 31360