Language: C++

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds; // find_by_order(), order_of_key()
template<typename TK> using pbds_set = tree<TK, null_type, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename TK, typename TV> using pbds_map = tree<TK, TV, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
*/
lint GetDigit(lint num);
lint GetDigit(lint num){
    return std::to_string(num).length();
}
struct point
{
    lint from;
    lint to;
    point(lint f,lint t)
    {
        from = f;
        to = t;
    };
};
int main()
{
    lint n;
    cin >> n;
    map<lint,point> gg;
    map<lint,lint> g;
    map<lint,lint> g2;
    REP(i,n - 1)
    {
        lint a,b;
        cin >> a >> b;
        gg[i] = point(a,b);
        g[a]++;
        g2[a]++;
        g[b]++;
        g2[b]++;
    }

lint currentMax = 0;
lint arg_max = 0;
for(auto it = g.cbegin(); it != g.cend(); ++it ) {
    if (it ->second > currentMax) {
        arg_max = it->first;
        currentMax = it->second;
    }
}
cout << currentMax << endl;
    REP(i,n - 1)
    {
        cout << g2[gg[i].from] - g[gg[i].from] + 1 << endl;
        g[gg[i].from]--;
        g[gg[i].to]--;
    }
}


Compiler output:
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/tuple: In instantiation of 'std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) [with _Args1 = {long long int&&}; long unsigned int ..._Indexes1 = {0}; _Args2 = {}; long unsigned int ..._Indexes2 = {}; _T1 = const long long int; _T2 = point]':
/usr/include/c++/14/tuple:2879:63:   required from 'std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {long long int&&}; _Args2 = {}; _T1 = const long long int; _T2 = point]'
 2879 |              typename _Build_index_tuple<sizeof...(_Args2)>::__type())
      |                                                                      ^
/usr/include/c++/14/bits/new_allocator.h:191:4:   required from 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::pair<const long long int, point>; _Args = {const std::piecewise_construct_t&, std::tuple<long long int&&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const long long int, point> >]'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<const long long int, point>; _Args = {const std::piecewise_construct_t&, std::tuple<long long int&&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const long long int, point> >; allocator_type = std::allocator<std::_Rb_tree_node<std::pair<const long long int, point> > >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:593:32:   required from 'void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_construct_node(_Link_type, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<long long int&&>, std::tuple<>}; _Key = long long int; _Val = std::pair<const long long int, point>; _KeyOfValue = std::_Select1st<std::pair<const long long int, point> >; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, point> >; _Link_type = std::_Rb_tree_node<std::pair<const long long int, point> >*]'
  593 |               _Alloc_traits::construct(_M_get_Node_allocator(),
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
  594 |                                        __node->_M_valptr(),
      |                                        ~~~~~~~~~~~~~~~~~~~~
  595 |                                        std::forward<_Args>(__args)...);
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:610:21:   required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<long long int&&>, std::tuple<>}; _Key = long long int; _Val = std::pair<const long long int, point>; _KeyOfValue = std::_Select1st<std::pair<const long long int, point> >; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, point> >; _Link_type = std::_Rb_tree_node<std::pair<const long long int, point> >*]'
  610 |           _M_construct_node(__tmp, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1633:32:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Auto_node::_Auto_node(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<long long int&&>, std::tuple<>}; _Key = long long int; _Val = std::pair<const long long int, point>; _KeyOfValue = std::_Select1st<std::pair<const long long int, point> >; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, point> >]'
 1633 |             _M_node(__t._M_create_node(std::forward<_Args>(__args)...))
      |                     ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:2460:13:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_hint_unique(const_iterator, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<long long int&&>, std::tuple<>}; _Key = long long int; _Val = std::pair<const long long int, point>; _KeyOfValue = std::_Select1st<std::pair<const long long int, point> >; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, point> >; iterator = std::_Rb_tree<long long int, std::pair<const long long int, point>, std::_Select1st<std::pair<const long long int, point> >, std::less<long long int>, std::allocator<std::pair<const long long int, point> > >::iterator; const_iterator = std::_Rb_tree<long long int, std::pair<const long long int, point>, std::_Select1st<std::pair<const long long int, point> >, std::less<long long int>, std::allocator<std::pair<const long long int, point> > >::const_iterator]'
 2460 |         _Auto_node __z(*this, std::forward<_Args>(__args)...);
      |                    ^~~
/usr/include/c++/14/bits/stl_map.h:532:37:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = point; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, point> >; mapped_type = point; key_type = long long int]'
  532 |           __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  533 |                                         std::forward_as_tuple(std::move(__k)),
      |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  534 |                                         std::tuple<>());
      |                                         ~~~~~~~~~~~~~~~
a.cc:64:13:   required from here
   64 |         gg[i] = point(a,b);
      |             ^
/usr/include/c++/14/tuple:2890:9: error: no matching function for call to 'point::point()'
 2890 |         second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:47:5: note: candidate: 'point::point(lint, lint)'
   47 |     point(lint f,lint t)
      |     ^~~~~
a.cc:47:5: note:   candidate expects 2 arguments, 0 provided
a.cc:43:8: note: candidate: 'constexpr point::point(const point&)'
   43 | struct point
      |        ^~~~~
a.cc:43:8: note:   candidate expects 1 argument, 0 provided
a.cc:43:8: note: candidate: 'constexpr point::point(point&&)'
a.cc:43:8: note:   candidate expects 1 argument, 0 provided