Language: C++

#include <bits/stdc++.h>
using namespace std;

#define vector<pair<int, int>> vp;
#define vector<int> vi;

void dfs(vp &edges,vi &ans, int par, int pc){
    int c = 1;
    for(auto p : edges[i]){
        int j = p.first, idx = p.second;
        if(j == par) continue;
        if(c == pc) c++;
        ans[idx] = c;
        dfs(edges,ans,j, i, c);
        c++;
    }
}

int main(){
    int N;
    cin >> N;
  	vp edges[N];
    vector<int> ans[N-1];
  	
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].emplace_back(b, i);
        edges[b].emplace_back(a, i);
    }
    dfs(edges,ans,0, -1, -1);
    cout << *max_element(ans, ans+N-1) << endl;
    for(int i=0; i<N-1; i++) cout << ans[i] << endl;
    return 0;
}


Compiler output:
a.cc:4:9: warning: ISO C++11 requires whitespace after the macro name
    4 | #define vector<pair<int, int>> vp;
      |         ^~~~~~
a.cc:5:9: warning: ISO C++11 requires whitespace after the macro name
    5 | #define vector<int> vi;
      |         ^~~~~~
a.cc:5:9: warning: "vector" redefined
a.cc:4:9: note: this is the location of the previous definition
    4 | #define vector<pair<int, int>> vp;
      |         ^~~~~~
a.cc:7:6: error: variable or field 'dfs' declared void
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |      ^~~
a.cc:7:10: error: 'vp' was not declared in this scope
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |          ^~
a.cc:7:14: error: 'edges' was not declared in this scope
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |              ^~~~~
a.cc:7:20: error: 'vi' was not declared in this scope
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |                    ^~
a.cc:7:24: error: 'ans' was not declared in this scope; did you mean 'abs'?
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |                        ^~~
      |                        abs
a.cc:7:29: error: expected primary-expression before 'int'
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |                             ^~~
a.cc:7:38: error: expected primary-expression before 'int'
    7 | void dfs(vp &edges,vi &ans, int par, int pc){
      |                                      ^~~
a.cc: In function 'int main()':
a.cc:22:9: error: 'vp' was not declared in this scope
   22 |         vp edges[N];
      |         ^~
a.cc:5:15: error: expected primary-expression before '<' token
    5 | #define vector<int> vi;
      |               ^
a.cc:23:5: note: in expansion of macro 'vector'
   23 |     vector<int> ans[N-1];
      |     ^~~~~~
a.cc:5:16: error: expected primary-expression before 'int'
    5 | #define vector<int> vi;
      |                ^~~
a.cc:23:5: note: in expansion of macro 'vector'
   23 |     vector<int> ans[N-1];
      |     ^~~~~~
a.cc:23:11: error: expected primary-expression before '<' token
   23 |     vector<int> ans[N-1];
      |           ^
a.cc:23:12: error: expected primary-expression before 'int'
   23 |     vector<int> ans[N-1];
      |            ^~~
a.cc:29:9: error: 'edges' was not declared in this scope
   29 |         edges[a].emplace_back(b, i);
      |         ^~~~~
a.cc:32:9: error: 'edges' was not declared in this scope
   32 |     dfs(edges,ans,0, -1, -1);
      |         ^~~~~
a.cc:32:15: error: 'ans' was not declared in this scope; did you mean 'abs'?
   32 |     dfs(edges,ans,0, -1, -1);
      |               ^~~
      |               abs
a.cc:32:5: error: 'dfs' was not declared in this scope; did you mean 'ffs'?
   32 |     dfs(edges,ans,0, -1, -1);
      |     ^~~
      |     ffs