Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
 
using graph = vector<vector<edge>>;
vector<bool> seen;
vector<ll> ans;
 
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
 
int main(){
    ll n;
    cin >> n;
    graph g(n);
    //graph edge(n);
    vector<vector<int>>hen(n);
    bool seen[n];
    rep(i,n){
        seen[i] = false;
    }
    int temp1,temp2;
    int ans[n-1];
    for(int i = 0; i < n; i++){
        cin >> temp1 >> temp2;
        g[temp1-1].push_back((edge){temp2-1,i});
        g[temp2-1].push_back((edge){temp1-1,i});
    }
    queue<int> que;
    que.push(0);
    seen[0] = true;
    int deg = -1;
    while(!que.empty()){
        int v = que.front();
        //seen[v] = true;
        que.pop();
        for(edge nv : g[v]){
            int k = 1;
            int index = 0;

            if(seen[nv.to]) continue;
            else{
                if(hen[v].size()){
                    //int index = hen[v].size()-1;
                    //int large = hen[v][index];
                    if(k == hen[v][index]){
                        k++;
                        index++;
                        while(k == hen[v][index]){
                            k++;
                            index++;
                        }
                    }
                    hen[v].push_back(k);
                    hen[nv.to].push_back(k);
                    ans[nv.id] = k;
                    k++;
                    }
                }
                else{
                    hen[v].push_back(1);
                    hen[nv.to].push_back(1);
                    ans[nv.id] = 1;
                }
 
            }
            que.push(nv.to);
            seen[nv.to] = true;
        }
        sort(hen.begin(),hen.end());
    }
 
    rep(i,n){
        deg = max(deg,(int)hen[i].size());
    }
    cout << deg << endl;
    rep(i,n-1){
        cout << ans[i] << endl;
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:73:17: error: 'else' without a previous 'if'
   73 |                 else{
      |                 ^~~~
a.cc:80:22: error: 'nv' was not declared in this scope; did you mean 'v'?
   80 |             que.push(nv.to);
      |                      ^~
      |                      v
a.cc: At global scope:
a.cc:7:19: error: expected unqualified-id before 'for'
    7 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:86:5: note: in expansion of macro 'rep'
   86 |     rep(i,n){
      |     ^~~
a.cc:86:9: error: 'i' does not name a type
   86 |     rep(i,n){
      |         ^
a.cc:7:35: note: in definition of macro 'rep'
    7 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:86:9: error: 'i' does not name a type
   86 |     rep(i,n){
      |         ^
a.cc:7:49: note: in definition of macro 'rep'
    7 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:89:5: error: 'cout' does not name a type
   89 |     cout << deg << endl;
      |     ^~~~
a.cc:7:19: error: expected unqualified-id before 'for'
    7 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                   ^~~
a.cc:90:5: note: in expansion of macro 'rep'
   90 |     rep(i,n-1){
      |     ^~~
a.cc:90:9: error: 'i' does not name a type
   90 |     rep(i,n-1){
      |         ^
a.cc:7:35: note: in definition of macro 'rep'
    7 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                   ^
a.cc:90:9: error: 'i' does not name a type
   90 |     rep(i,n-1){
      |         ^
a.cc:7:49: note: in definition of macro 'rep'
    7 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                                 ^
a.cc:93:1: error: expected declaration before '}' token
   93 | }
      | ^