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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define  nl "\n"
#define forn(a, c) for (int a = 0; a < c; a++) 
#define forl(a, b, c) for (int a = b; a <= c; a++) 
#define forr(a, b, c) for (int a = b; a >= c; a--)
#define cin(v) for(auto &i:v){cin>>i;}
#define cout(v) for(auto &i:v){cout<<i<<" ";}cout<<nl;
#define all(a) a.begin(),a.end()
#define fast() (ios_base::sync_with_stdio(false), cin.tie(NULL));
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int n;cin>>n;
    // std::vector<pair<int,int>> v(n);
    map<int,int> edge;
    map<int,int> mp;
    int mx = 0;
    int e1 = 0;
    forn(i,n-1){
        int x,y;cin>>x>>y;
        edge[x] = y;
        mp[x]++;
        mp[y]++;
        if( mx < mp[x]){mx = mp[x];e1 = x;}
        if(mx < mp[y]){mx = mp[y];e1 = y;}
    }
    // for(auto &i:edge){
    //     cout<<i.first<<' '<<i.second<<nl;
    // }
    int mx2 = 0;
    int e2 = 0;
    for(auto &i:mp){
        if(mx-mx2 > mx-i.second && e1 != i.first){mx2 = i.second;e2 = i.first;}
    }
    // cout<<mx<<" "<<mx2<<nl;
    // cout<<e2<<nl;
    int c = mx2 + mx -1;
    if(edge[e1] == e2 || edge[e2] == e1)c--;
    cout<<c<<nl;
}

signed main()
{
    auto begin = std::chrono::high_resolution_clock::now();
    fast();
    int tt;cin>>tt;
    while(tt--){
        solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define  nl "\n"
#define forn(a, c) for (int a = 0; a < c; a++) 
#define forl(a, b, c) for (int a = b; a <= c; a++) 
#define forr(a, b, c) for (int a = b; a >= c; a--)
#define cin(v) for(auto &i:v){cin>>i;}
#define cout(v) for(auto &i:v){cout<<i<<" ";}cout<<nl;
#define all(a) a.begin(),a.end()
#define fast() (ios_base::sync_with_stdio(false), cin.tie(NULL));
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int n;cin>>n;
    std::vector<pair<int,int>> v;
    map<int,int> mp;
    int mx = 0;
    int e1 = 0;
    forn(i,n-1){
        int x,y;cin>>x>>y;
        v.push_back({x,y});
        mp[x]++;
        mp[y]++;
        if( mx < mp[x]){mx = mp[x];e1 = x;}
        if(mx < mp[y]){mx = mp[y];e1 = y;}
    }
    sort(v.begin(),v.end());
    int mx2 = 0;
    int e2 = 0;
    for(auto &i:mp){
        if(mx-mx2 > mx-i.second && e1 != i.first){mx2 = i.second;e2 = i.first;}
    }
    // cout<<mx<<" "<<mx2<<nl;
    // cout<<e1<<" "<<e2<<nl;
    int c = mx2 + mx -1;
    // cout<<edge[e1]<<nl;
    bool flag = false;
    pair<int,int> p = {e1,e2};
    pair<int,int> pp = {e2,e1};
    // cout<<binary_search(v.begin(),v.end(),p)<<nl;
    if(binary_search(v.begin(),v.end(),p) || binary_search(v.begin(),v.end(),pp)) flag = true;
    if(flag)c--;
    cout<<c<<nl;
}

signed main()
{
    auto begin = std::chrono::high_resolution_clock::now();
    fast();
    int tt;cin>>tt;
    while(tt--){
        solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
}