Language: C++

v#include <bits/stdc++.h>

using namespace std;

#define int long long

map <pair <int, int>, int> ed;
vector <int> ans;
vector <vector <int> > g;

void dfs(int v, int p, int col) {
    int stc = 1;
    if (col == stc) ++stc;
    for (auto u : g[v]) {
        if (u != p) {
            ans[ed[{min(v, u), max(v, u)}]] = stc;
            dfs(u, v, stc);
            ++stc;
            if (stc == col) ++stc;
        }
    }
}

void solve() {
    int n;
    cin >> n;
    g.resize(n);
    ans.resize(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        int v, u;
        cin >> v >> u;
        --v;
        --u;
        if (v > u) swap(v, u);
        g[v].push_back(u);
        g[u].push_back(v);
        ed[{v, u}] = i;
    }
    int st = 0;
    for (int i = 1; i < n; ++i) if (g[st].size() < g[i].size()) st = i;
    cout << g[st].size() << '\n';
    dfs(st, -1, 0);
    for (int i = 0; i < n - 1; ++i) cout << ans[i] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | v#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'v' does not name a type
    1 | v#include <bits/stdc++.h>
      | ^
a.cc:7:1: error: 'map' does not name a type
    7 | map <pair <int, int>, int> ed;
      | ^~~
a.cc:8:1: error: 'vector' does not name a type
    8 | vector <int> ans;
      | ^~~~~~
a.cc:9:1: error: 'vector' does not name a type
    9 | vector <vector <int> > g;
      | ^~~~~~
a.cc: In function 'void dfs(long long int, long long int, long long int)':
a.cc:14:19: error: 'g' was not declared in this scope
   14 |     for (auto u : g[v]) {
      |                   ^
a.cc:16:13: error: 'ans' was not declared in this scope
   16 |             ans[ed[{min(v, u), max(v, u)}]] = stc;
      |             ^~~
a.cc:16:17: error: 'ed' was not declared in this scope
   16 |             ans[ed[{min(v, u), max(v, u)}]] = stc;
      |                 ^~
a.cc:16:21: error: 'min' was not declared in this scope
   16 |             ans[ed[{min(v, u), max(v, u)}]] = stc;
      |                     ^~~
a.cc:16:32: error: 'max' was not declared in this scope
   16 |             ans[ed[{min(v, u), max(v, u)}]] = stc;
      |                                ^~~
a.cc: In function 'void solve()':
a.cc:26:5: error: 'cin' was not declared in this scope
   26 |     cin >> n;
      |     ^~~
a.cc:27:5: error: 'g' was not declared in this scope
   27 |     g.resize(n);
      |     ^
a.cc:28:5: error: 'ans' was not declared in this scope
   28 |     ans.resize(n - 1);
      |     ^~~
a.cc:34:20: error: 'swap' was not declared in this scope
   34 |         if (v > u) swap(v, u);
      |                    ^~~~
a.cc:37:9: error: 'ed' was not declared in this scope
   37 |         ed[{v, u}] = i;
      |         ^~
a.cc:41:5: error: 'cout' was not declared in this scope
   41 |     cout << g[st].size() << '\n';
      |     ^~~~
a.cc: In function 'int main()':
a.cc:47:5: error: 'ios_base' has not been declared
   47 |     ios_base::sync_with_stdio(false);
      |     ^~~~~~~~
a.cc:48:5: error: 'cin' was not declared in this scope
   48 |     cin.tie(0);
      |     ^~~
a.cc:49:5: error: 'cout' was not declared in this scope
   49 |     cout.tie(0);
      |     ^~~~