Language: C++

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int N;
int a[110000];
int b[110000];
int color[110000][110000];

int color_num;
vector<bool> seen;
using Graph = vector<vector<int>>;


void dfs(Graph& G, int v) {
  seen[v] = true;

  vector<bool> used(110000);
  for (auto next_v : G[v]) {
    int tmp = max(color[v][next_v], color[next_v][v]);

    if (tmp != 0) used[tmp] = true;
    else {
      rep(k, color_num) {
        if (!used[k]) {
          color[v][next_v] = k;
          used[k] = true;
          break;
        }
      }
    }
  } 

  for (auto next_v : G[v]) {
    if (seen[next_v]) continue;

    dfs(G, next_v);
  }
}

int main () {
  cin >> N;
  Graph G(N+1);

  rep(i, N-1) {
    int s, t;
    cin >> s >> t;
    a[i] = s;
    b[i] = t;

    G[s].push_back(t);
    G[t].push_back(s);
  }

  color_num = 0;
  rep(i, N) {
    int l = G[i].size();
    color_num = max(color_num, l);
  }

  seen.assign(N+1, false);

  dfs(G, 1);

  cout << color_num << "\n";
  rep(i, N-1) {
    cout << max(color[a[i]][b[i]], color[b[i]][a[i]]) << "\n";
  }
}

Compiler output:
/tmp/ccVTz8vC.o: in function `dfs(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, int)':
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x230): relocation truncated to fit: R_X86_64_PC32 against symbol `color_num' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x2d3): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccVTz8vC.o
/tmp/ccVTz8vC.o: in function `main':
a.cc:(.text+0x4b5): relocation truncated to fit: R_X86_64_PC32 against symbol `color_num' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x4f0): relocation truncated to fit: R_X86_64_PC32 against symbol `color_num' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x500): relocation truncated to fit: R_X86_64_PC32 against symbol `color_num' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x52c): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x54b): relocation truncated to fit: R_X86_64_PC32 against symbol `color_num' defined in .bss section in /tmp/ccVTz8vC.o
/tmp/ccVTz8vC.o: in function `__static_initialization_and_destruction_0()':
a.cc:(.text+0x6bc): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccVTz8vC.o
a.cc:(.text+0x6d5): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccVTz8vC.o
collect2: error: ld returned 1 exit status