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;
typedef long long ll;
typedef long double ld;
#define pl pair<ll,ll>
#define ml map<ll,ll>
#define fr first
#define sc second
#define pb push_back
ll idx,cnt,n,m,in[200005];
pl pr[200005];
/*/ ------------------------------------------------///
//  $$ - - - * * * - - - * * * - - - * * * - - - $$

  ______  _______  _____  __   __  _______  __   _
 |_____/  |_____|    |      \_/    |_____|  | \  |
 |    \_  |     |  __|__     |     |     |  |  \_|


//  $$ - - - * * * - - - * * * - - - * * * - - - $$\
// ------------------------------------------------*///
ll mx=1e6+7,md=1e9+7,bs=29; string s;
ll fnd(ll x) {return (in[x]==x)?x:in[x]=fnd(in[x]);}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1,x=1,i,j,tc=1;  cin>>t; 
    while(t--){ cnt=0; ml mp; map<pl,ll> mp1;
    ll i,n1,k=0,j=0,ct=0,x=0,y=0,q=1,z=0;
    cin>>n; pl pr1[n-1];
    for(i=1;i<=n;i++) pr[i].fr=0,pr[i].sc=i,in[i]=i;
    for(i=0;i<n-1;i++){
        cin>>x>>y; if(x>y) swap(x,y);
        pr[x].fr++,pr[y].fr++;
        pr1[i]={x,y}; mp1[{x,y}]=1;}
    sort(pr+1,pr+1+n); set<ll> st; vector<ll> v;
    for(i=n;i>0;i--) {if(pr[i].fr==pr[n].fr) v.pb(pr[i].sc);}
    
    if(v.size()==1){mp[pr[n].sc]=1,x=n-1; 
while(pr[x].fr==pr[n-1].fr&&x>0&&mp1[{min(pr[x].sc,pr[n].sc),max(pr[x].sc,pr[n].sc)}]) x--;
    if(pr[x].fr==pr[n-1].fr) mp[pr[x].sc]=1; else mp[pr[n-1].sc]=1;}
    
    else{
    for(i=0;i<v.size();i++) for(j=0;j<v.size();j++){
    if(i==j) continue; x=pr[v[i]].sc,y=pr[v[j]].sc;
    if(mp1[{min(x,y),max(x,y)}]==0) {ct=1; mp[x]=1,mp[y]=1; break;}}
    if(!ct) mp[pr[n].sc]=1,mp[pr[n-1].sc]=1; }
    
    for(i=0;i<n-1;i++){ x=pr1[i].fr,y=pr1[i].sc;
    if(mp[x]) {in[x]=-1; if(mp[y]) in[y]=-1;
    continue;}
    if(mp[y]) {in[y]=-1; if(mp[x]) in[x]=-1; continue;}
    in[fnd(x)]=fnd(y); }
    for(i=1;i<=n;i++) {if(mp[i]) continue; st.insert(fnd(i));}
    cout<<st.size()<<'\n';
}}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pl pair<ll,ll>
#define ml map<ll,ll>
#define fr first
#define sc second
#define pb push_back
ll idx,cnt,n,m,in[200005];
pl pr[200005];
/*/ ------------------------------------------------///
//  $$ - - - * * * - - - * * * - - - * * * - - - $$

  ______  _______  _____  __   __  _______  __   _
 |_____/  |_____|    |      \_/    |_____|  | \  |
 |    \_  |     |  __|__     |     |     |  |  \_|


//  $$ - - - * * * - - - * * * - - - * * * - - - $$\
// ------------------------------------------------*///
ll mx=1e6+7,md=1e9+7,bs=29; string s;
ll fnd(ll x) {return (in[x]==x)?x:in[x]=fnd(in[x]);}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1,x=1,i,j,tc=1;  cin>>t; 
    while(t--){ cnt=0; ml mp; map<pl,ll> mp1;
    ll i,n1,k=0,j=0,ct=0,x=0,y=0,q=1,z=0;
    cin>>n; pl pr1[n-1];
    for(i=1;i<=n;i++) pr[i].fr=0,pr[i].sc=i,in[i]=i;
    for(i=0;i<n-1;i++){
        cin>>x>>y; if(x>y) swap(x,y);
        pr[x].fr++,pr[y].fr++;
        pr1[i]={x,y}; mp1[{x,y}]=1;}
    sort(pr+1,pr+1+n); set<ll> st; vector<ll> v;
    for(i=n;i>0;i--) {if(pr[i].fr==pr[n].fr) v.pb(pr[i].sc);}
    
    if(v.size()==1){mp[pr[n].sc]=1,x=n-1; 
while(pr[x].fr==pr[n-1].fr&&x>0&&mp1[{min(pr[x].sc,pr[n].sc),max(pr[x].sc,pr[n].sc)}]) x--;
    if(pr[x].fr==pr[n-1].fr) mp[pr[x].sc]=1; else mp[pr[n-1].sc]=1;}
    
    else{
    for(i=0;i<v.size();i++) for(j=0;j<v.size();j++){
    if(i==j) continue; 
    if(mp1[{min(v[i],v[j]),max(v[i],v[j])}]==0) {ct=1; mp[v[i]]=1,mp[v[j]]=1; break;}}
    if(!ct) mp[pr[n].sc]=1,mp[pr[n-1].sc]=1; }
    
    for(i=0;i<n-1;i++){ x=pr1[i].fr,y=pr1[i].sc;
    if(mp[x]) {in[x]=-1; if(mp[y]) in[y]=-1;
    continue;}
    if(mp[y]) {in[y]=-1; if(mp[x]) in[x]=-1; continue;}
    in[fnd(x)]=fnd(y); }
    for(i=1;i<=n;i++) {if(mp[i]) continue; st.insert(fnd(i));}
    cout<<st.size()<<'\n';
}}