Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<numeric>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define int long long 
#define endl "\n"
#define ff  first
#define ss second
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define pq priority_queue
#define pqv priority_queue<int, vector<int>, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
#define ninf -1e18
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define mod 1000000007
#define mod1 1000000009
#define mod2 998244353
#define mod3 1000000007
#define mod4 1000000009
#define mod5 1000000021
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;

signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<vector<int>> adj(n+1);
        vector<int> degree(n+1,0);
        multiset<int> ms;
        for(int i=1;i<n;i++)
        {
            int u,v;
            cin>>u>>v;
            adj[u].push_back(v);
            adj[v].push_back(u);
            degree[u]++;
            degree[v]++;
        }
        for(int i=1;i<=n;i++)
        {
            ms.insert(degree[i]);
        }
        int maxi=INT_MIN;
        for(int i=1;i<=n;i++)
        {
            int curr=0;
            int curr_node=i;
            ms.extract(degree[i]);
            for(auto neigh:adj[curr_node])
            {
                ms.extract(degree[neigh]);
                degree[neigh]--;
                ms.insert(degree[neigh]);
            }
            int temp= degree[curr_node]+(*ms.rbegin());
            maxi=max(maxi,temp);
            for(auto neigh:adj[curr_node])
            {
                ms.extract(degree[neigh]);
                degree[neigh]++;
                ms.insert(degree[neigh]);
            }
        }
        cout<<maxi-1<<endl;
    }
    return 0;
}

Submission (verdict: Compilation error):
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<numeric>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define int long long 
#define endl "\n"
#define ff  first
#define ss second
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mt make_tuple
#define pq priority_queue
#define pqv priority_queue<int, vector<int>, greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define inf 1e18
#define ninf -1e18
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define mod 1000000007
#define mod1 1000000009
#define mod2 998244353
#define mod3 1000000007
#define mod4 1000000009
#define mod5 1000000021
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
void solve() 
{
    int n;
    cin>>n;
    vector<vector<int>> adj(n+1);
    vector<int> degree(n+1,0);
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }
    if(n<=2)
    {
        cout<<0<<endl;
        return;
    }
    multiset<int> degree_set;
    for(int i=1;i<=n;i++)
    {
        degree_set.insert(degree[i]);
    }
    int max_componenent=1;
    for(int i=1;i<=n;i++)
    {
        int curr_degree= degree[i];
        auto it = degree_set.find(degree[i]);
        degree_set.erase(it);
        for(auto node:adj[i])
        {
            auto it = degree_set.find(degree[node]);
            degree_set.erase(it);
            degree[node]--;
            degree_set.insert(degree[node]);
        }
        int temp= *degree_set.rbegin()-1+degree[i]-1+1;
        max_componenent=max(max_componenent,temp);
        degree_set.insert(degree[i]);
        for(auto node:adj[i])
        {
            auto it = degree_set.find(degree[node]);
            degree_set.erase(it);
            degree[node]++;
            degree_set.insert(degree[node]);

        }
    }
    cout<<max_componenent<<endl;
    
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n = 1;
    cin >> n;
    for (int t = 1; t <= n; t++) {
        solve();
    }
    return 0;
}