Problem: 2063C - Remove Exactly Two
Language: c++20 

Code 1:
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
ll M = 1e9+7;
const ll N = 2e5 + 5;
#define pb push_back
#define in insert
#define vll vector<ll>
#define pll pair<ll,ll>
#define vbl vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define sll set<ll> 
#define all(c) c.begin(),c.end()
#define msll multiset<ll>
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define geta(c,n) ll c[n]; for(ll i=0;i<n;i++)cin>>c[i];
#define endl "\n"

int main(){
    ll tt = 1 ;
    cin >> tt ;
    while(tt--){
        ll n ; cin >> n ; 
        map<pll,ll> m ; 
        vpll v;
        ll ct[n+1]={0};
        rep(i,n-1){
            ll x,y ; cin >> x>> y;
            ct[x]++;
            ct[y]++;
            m[{x,y}]++;
            m[{y,x}]++;
        }
        rep1(i,n)v.pb({ct[i],i});
        sort(all(v));
        reverse(all(v));
        ll ans = v[0].first;
        rep1(i,v.size()-1){
            if(m[{v[0].second,v[i].second}])ans=max(ans,v[0].first+v[i].first-1);
            else ans=max(ans,v[0].first+v[i].first);
        }
        cout<<ans-1<<endl;
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
ll M = 1e9+7;
const ll N = 2e5 + 5;
#define pb push_back
#define in insert
#define vll vector<ll>
#define pll pair<ll,ll>
#define vbl vector<bool>
#define vpll vector<pair<ll,ll>>
#define vvll vector<vector<ll>>
#define sll set<ll> 
#define all(c) c.begin(),c.end()
#define msll multiset<ll>
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define geta(c,n) ll c[n]; for(ll i=0;i<n;i++)cin>>c[i];
#define endl "\n"

int main(){
    ll tt = 1 ;
    cin >> tt ;
    while(tt--){
        ll n ; cin >> n ; 
        map<pll,ll> m ; 
        vpll v;
        ll ct[n+1]={0};
        rep(i,n-1){
            ll x,y ; cin >> x>> y;
            ct[x]++;
            ct[y]++;
            m[{x,y}]++;
            m[{y,x}]++;
        }
        rep1(i,n)v.pb({ct[i],i});
        sort(all(v));
        reverse(all(v));
        ll ans = v[0].first;
        rep1(i,v.size()-1){
            if(m[{v[0].second,v[i].second}])ans=max(ans,v[0].first+v[i].first-1);
            else ans=max(ans,v[0].first+v[i].first);
            if(i>1){
                if(m[{v[1].second,v[i].second}])ans=max(ans,v[1].first+v[i].first-1);
                else ans=max(ans,v[1].first+v[i].first);
            }
        }
        cout<<ans-1<<endl;
    }
}

Answer: 2