#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg(x) cout << #x << " : " << x << endl
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define maxn 100005
vector<ll> edges[maxn];
ll n;
ll dem = 0;
ll dau[maxn];
ll check[maxn], point_edges[maxn];
map<pair<ll, ll>, ll> mapping;
ll maax = 0;
ll bd;
struct cap
{
ll x, y;
};
void bfs(ll source)
{
dau[source] = 1;
queue<ll> q;
q.push(source);
while (!q.empty())
{
ll p = q.front();
q.pop();
bd = point_edges[p] + 1;
for (auto v : edges[p])
{
if (dau[v] == 1)
continue;
dau[v] = 1;
mapping[{p, v}] = mapping[{v, p}] = point_edges[v] = bd % maax;
// cout<<"("<<p+1<<","<<v+1<<"):"<<bd%maax<<'\n';
bd++;
q.push(v);
}
}
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
memset(point_edges, -1, sizeof(point_edges));
cin >> n;
cap a[n];
for (ll i = 0; i < n - 1; i++)
{
ll u, v;
cin >> u >> v;
u--, v--;
edges[u].push_back(v);
edges[v].push_back(u);
a[i].x = u;
a[i].y = v;
mapping[{u, v}] = -1;
mapping[{v, u}] = -1;
}
ll vt;
for (ll i = 0; i < n; i++)
{
// cout<<i+1<<"-->";
// for(auto v: edges[i]) cout<<v<<" ";
// cout<<'\n';
ll tmp = edges[i].size();
if (tmp > maax)
{
maax = tmp;
vt = i;
}
}
cout << maax << '\n';
bfs(0);
// cout<<"--------\n";
for (ll i = 0; i < n - 1; i++)
cout << mapping[{a[i].x, a[i].y}] + 1 << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZGJnKHgpIGNvdXQgPDwgI3ggPDwgIiA6ICIgPDwgeCA8PCBlbmRsCiNkZWZpbmUgcmVwKGksIGEsIGIpIGZvciAoaW50IGkgPSAoYSk7IGkgPD0gKGI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ludF9lZGdlcykpOwogICAgY2luID4+IG47CiAgICBjYXAgYVtuXTsKICAgIGZvciAobGwgaSA9IDA7IGkgPCBuIC0gMTsgaSsrKQogICAgewogICAgICAgIGxsIHUsIHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICB1LS0sIHYtLTsKICAgICAgICBlZGdlc1t1XS5wdXNoX2JhY2sodik7CiAgICAgICAgZWRnZXNbdl0ucHVzaF9iYWNrKHUpOwogICAgICAgIGFbaV0ueCA9IHU7CiAgICAgICAgYVtpXS55ID0gdjsKICAgICAgICBtYXBwaW5nW3t1LCB2fV0gPSAtMTsKICAgICAgICBtYXBwaW5nW3t2LCB1fV0gPSAtMTsKICAgIH0KCiAgICBsbCB2dDsKICAgIGZvciAobGwgaSA9IDA7IGkgPCBuOyBpKyspCiAgICB7CiAgICAgICAgLy8gY291dDw8aSsxPDwiLS0+IjsKICAgICAgICAvLyBmb3IoYXV0byB2OiBlZGdlc1tpXSkgY291dDw8djw8IiAiOwogICAgICAgIC8vIGNvdXQ8PCdcbic7CiAgICAgICAgbGwgdG1wID0gZWRnZXNbaV0uc2l6ZSgpOwogICAgICAgIGlmICh0bXAgPiBtYWF4KQogICAgICAgIHsKICAgICAgICAgICAgbWFheCA9IHRtcDsKICAgICAgICAgICAgdnQgPSBpOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgbWFheCA8PCAnXG4nOwogICAgYmZzKDApOwogICAgLy8gY291dDw8Ii0tLS0tLS0tXG4iOwogICAgZm9yIChsbCBpID0gMDsgaSA8IG4gLSAxOyBpKyspCiAgICAgICAgY291dCA8PCBtYXBwaW5nW3thW2ldLngsIGFbaV0ueX1dICsgMSA8PCAnXG4nOwogICAgcmV0dXJuIDA7Cn0=