Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    int N, a, b;
    cin >> N;
    vector<vector<int>> E(N);
    vector<pair<int, int>> V;
    rep(i, N - 1) {
        cin >> a >> b;
        a--;
        b--;
        E[a].eb(b);
        E[b].eb(a);
        V.eb(a, b);
    }
    int max_c = 0;
    rep(i, N) max_c = max(max_c, (int)E[i].size());

    map<pair<int, int>, int> D;
    vector<bool> used(N, false);
    queue<int> q({0});
    vector<priority_queue<int, vector<int>, greater<int>>> PQ(N);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int c = 0;
        for (auto e : E[x]) {
        	if(used[e])continue;
            while (!PQ[x].empty()) {
                if (c != PQ[x].top()) break;
                PQ[x].pop();
                c++;
            }
            PQ[e].emplace(c);
            q.emplace(e);
            D[make_pair(x, e)] = D[make_pair(e, x)] = c++;
        }
        used[x] = true;
    }
    cout << max_c << endl;
    for (auto v : V) cout << D[v] + 1 << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:5: error: 'queue' was not declared in this scope
   45 |     queue<int> q({0});
      |     ^~~~~
a.cc:7:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    6 | #include <iomanip>
  +++ |+#include <queue>
    7 | using namespace std;
a.cc:45:11: error: expected primary-expression before 'int'
   45 |     queue<int> q({0});
      |           ^~~
a.cc:45:21: error: expected primary-expression before ')' token
   45 |     queue<int> q({0});
      |                     ^
a.cc:46:12: error: 'priority_queue' was not declared in this scope
   46 |     vector<priority_queue<int, vector<int>, greater<int>>> PQ(N);
      |            ^~~~~~~~~~~~~~
a.cc:46:12: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
a.cc:46:56: error: template argument 1 is invalid
   46 |     vector<priority_queue<int, vector<int>, greater<int>>> PQ(N);
      |                                                        ^~
a.cc:46:56: error: template argument 2 is invalid
a.cc:46:58: error: expected unqualified-id before '>' token
   46 |     vector<priority_queue<int, vector<int>, greater<int>>> PQ(N);
      |                                                          ^
a.cc:47:13: error: 'q' was not declared in this scope
   47 |     while (!q.empty()) {
      |             ^
a.cc:53:21: error: 'PQ' was not declared in this scope
   53 |             while (!PQ[x].empty()) {
      |                     ^~
a.cc:58:13: error: 'PQ' was not declared in this scope
   58 |             PQ[e].emplace(c);
      |             ^~