Language: C++

include <bits/stdc++.h>
using namespace std;
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; }

using Edge = pair<int,int>; // (隣接頂点, 辺番号)
using Graph = vector<vector<Edge>>;
int N;
Graph G;

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].emplace_back(b, i); 
        G[b].emplace_back(a, i);
    }
    int max_color = 0;
    for (int i = 0; i < N; ++i) chmax(max_color, (int)G[i].size());
    vector<int> res(N-1, -1);

    vector<int> dist(N, -1);
    queue<pair<int,int>> que; // (頂点, 前回の色)
    que.push({0, -1});
    dist[0] = 0;
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        int v = p.first, c = p.second;
        int color = 1;
        if (color == c) ++color;
        for (auto e : G[v]) {
            if (dist[e.first] == -1) {
                dist[e.first] = dist[v] + 1;
                que.push({e.first, color});
                res[e.second] = color;
                ++color;
                if (color == c) ++color;
            }
        }
    }
    cout << max_color << endl;
    for (auto v : res) cout << v << endl;
}

Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
a.cc:6:14: error: 'pair' does not name a type
    6 | using Edge = pair<int,int>; // (隣接頂点, 辺番号)
      |              ^~~~
a.cc:7:15: error: 'vector' does not name a type
    7 | using Graph = vector<vector<Edge>>;
      |               ^~~~~~
a.cc:9:1: error: 'Graph' does not name a type
    9 | Graph G;
      | ^~~~~
a.cc: In function 'int main()':
a.cc:12:5: error: 'cin' was not declared in this scope
   12 |     cin >> N;
      |     ^~~
a.cc:13:5: error: 'G' was not declared in this scope
   13 |     G.assign(N, vector<Edge>());
      |     ^
a.cc:13:17: error: 'vector' was not declared in this scope
   13 |     G.assign(N, vector<Edge>());
      |                 ^~~~~~
a.cc:13:24: error: 'Edge' was not declared in this scope
   13 |     G.assign(N, vector<Edge>());
      |                        ^~~~
a.cc:13:30: error: expected primary-expression before ')' token
   13 |     G.assign(N, vector<Edge>());
      |                              ^
a.cc:21:12: error: expected primary-expression before 'int'
   21 |     vector<int> res(N-1, -1);
      |            ^~~
a.cc:23:12: error: expected primary-expression before 'int'
   23 |     vector<int> dist(N, -1);
      |            ^~~
a.cc:24:5: error: 'queue' was not declared in this scope
   24 |     queue<pair<int,int>> que; // (頂点, 前回の色)
      |     ^~~~~
a.cc:24:11: error: 'pair' was not declared in this scope
   24 |     queue<pair<int,int>> que; // (頂点, 前回の色)
      |           ^~~~
a.cc:24:16: error: expected primary-expression before 'int'
   24 |     queue<pair<int,int>> que; // (頂点, 前回の色)
      |                ^~~
a.cc:25:5: error: 'que' was not declared in this scope
   25 |     que.push({0, -1});
      |     ^~~
a.cc:26:5: error: 'dist' was not declared in this scope
   26 |     dist[0] = 0;
      |     ^~~~
a.cc:31:22: error: 'c' was not declared in this scope
   31 |         if (color == c) ++color;
      |                      ^
a.cc:36:17: error: 'res' was not declared in this scope
   36 |                 res[e.second] = color;
      |                 ^~~
a.cc:38:30: error: 'c' was not declared in this scope
   38 |                 if (color == c) ++color;
      |                              ^
a.cc:42:5: error: 'cout' was not declared in this scope
   42 |     cout << max_color << endl;
      |     ^~~~
a.cc:42:26: error: 'endl' was not declared in this scope
   42 |     cout << max_color << endl;
      |                          ^~~~
a.cc:43:19: error: 'res' was not declared in this scope
   43 |     for (auto v : res) cout << v << endl;
      |                   ^~~