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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define x first
#define y second
#define int long long

const int MAXN = 2e5 + 100;
vector<int> g[MAXN];

int power[MAXN];
int used[MAXN];

void dfs(int v) {
    used[v] = 1;
    for (int u : g[v]) {
        if (used[u] != 1) {
            dfs(u);
        }
    }
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        used[i] = 0;
    }
    set<pair<int, int>> s;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
        s.insert({u, v});
    }
    for (int i = 0; i < n; i++) {
        power[i] = g[i].size();
    }
    int mx = -1;
    for (int i = 0; i < n; i++) {
        mx = max(mx, power[i]);
    }
    for (int i = 0; i < n; i++) {
        if (power[i] == mx) {
            used[i] = 1;
            for (int u : g[i]) {
                power[u]--;
            }
            break;
        }
    }
    mx = -1;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            mx = max(mx, power[i]);
        }
    }
    for (int i = 0; i < n; i++) {
        if (power[i] == mx && !used[i]) {
            used[i] = 1;
            for (int u : g[i]) {
                power[u]--;
            }
            break;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i);
            ans++;
        }
    }
    cout << ans << '\n';
}

signed main() {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define x first
#define y second
#define int long long

const int MAXN = 2e5 + 100;
vector<int> g[MAXN];

int power[MAXN];
int used[MAXN];

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        power[i] = 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    set<pair<int, int>> s;
    for (int i = 0; i < n; i++) {
        power[i] = g[i].size();
        s.insert({power[i], i});
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int u : g[i]) {
            s.erase({-power[u], u});
            power[u]--;
            s.insert({-power[u], u});
        }
        s.erase({-power[i], i});
        ans = max(ans, power[i] + -(s.begin()->x) - 1);
        s.insert({power[i], i});
        for (int u : g[i]) {
            s.erase({-power[u], u});
            power[u]++;
            s.insert({-power[u], u});
        }
    }
    cout << ans << '\n';
}

signed main() {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}