Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vll S_flag;
map<pair<ll, ll>, ll> C_mp;
vvll T;

void search(ll pos){
  if(S_flag[pos]>0) return;
  S_flag[pos] = 1;
  set<ll> used_color;
  for(ll i=0; i<T[pos].size(); ++i){
    pair<ll, ll> p1(pos, T[pos][i]);
    if(C_mp.find(p1)!=C_mp.end()) used_color.emplace(C_mp[p1]);
  }
  ll color=1;
  for(ll i=0; i<T[pos].size(); ++i){
    pair<ll, ll> p1(pos, T[pos][i]);
    if(C_mp.find(p1)!=C_mp.end()) continue;
    while(used_color.find(color)!=used_color.end()) color++;
    pair<ll, ll> p2(T[pos][i], pos);
    C_mp[p1] = color;
    C_mp[p2] = color;
  }
  for(ll i=0; i<T[pos].size(); ++i) search(T[pos][i]);
  return;
}

int main(void){
  ll N;
  cin >> N;
  T.resize(N);
  vll a(N-1), b(N-1);
  for(ll i=0; i<N-1; ++i){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    T[a[i]].push_back(b[i]);
    T[b[i]].push_back(a[i]);
  }
  
  ll K = 0;
  for(ll i=0; i<N; ++i) K = max(K, T[i].size());
  
  S_flag.resize(N, 0);
  
  search(0);
  
  cout << K << endl;
  for(ll i=0; i<N-1; ++i){
    pair<ll, ll> p1(a[i], b[i]);
    cout << C_mp[p1] << endl;
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:45:32: error: no matching function for call to 'max(ll&, std::vector<long long int>::size_type)'
   45 |   for(ll i=0; i<N; ++i) K = max(K, T[i].size());
      |                             ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:45:32: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'})
   45 |   for(ll i=0; i<N; ++i) K = max(K, T[i].size());
      |                             ~~~^~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:45:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   45 |   for(ll i=0; i<N; ++i) K = max(K, T[i].size());
      |                             ~~~^~~~~~~~~~~~~~~~