Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll int64_t
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;

        vector<unordered_set<int>> adj(n + 1);
        for (int i = 0; i < n - 1; i++)
        {
            int first, second;
            cin >> first >> second;
            adj[first].insert(second);
            adj[second].insert(first);
        }
        int maxi = 0, index = 0;

        for (int i = 1; i <= n; i++)
        {
            int key = i;
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.size() > maxi)
            {
                maxi = neighbors.size();
                index = key;
            }
        }
        unordered_set<int> &byebye = adj[index];
        // cout << index << endl;
        for (auto a : byebye)
        {
            int currele = a;
            adj[currele].erase(index);
        }
        byebye.clear();
        byebye.insert(-1);

        maxi = -1, index = 0;

        for (int i = 1; i <= n; i++)
        {
            int key = i;
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.count(-1))
            {
                // cout << i << endl;
                continue;
            }

            if ((int)neighbors.size() > maxi)
            {

                maxi = neighbors.size();
                index = i;
            }
        }

        unordered_set<int> &byebye2 = adj[index];
        // cout << index << endl;
        for (auto a : byebye2)
        {
            int currele = a;
            adj[currele].erase(index);
        }
        byebye2.clear();
        byebye2.insert(-1);
        int res = 0;
        unordered_set<int> selected;
        for (int i = 1; i <= n; i++)
        {
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.count(-1) || selected.count(i))
                continue;
            selected.insert(i);
            for (auto a : neighbors)
            {
                selected.insert(a);
            }
            res++;
        }
        cout << res << endl;
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll int64_t
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;

        vector<unordered_set<int>> adj(n + 1);
        for (int i = 0; i < n - 1; i++)
        {
            int first, second;
            cin >> first >> second;
            adj[first].insert(second);
            adj[second].insert(first);
        }
        int maxi = 0, index = 0;

        for (int i = 1; i <= n; i++)
        {
            int key = i;
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.size() >= maxi)
            {
                maxi = neighbors.size();
                index = key;
            }
        }
        unordered_set<int> &byebye = adj[index];
        // cout << index << endl;
        for (auto a : byebye)
        {
            int currele = a;
            adj[currele].erase(index);
        }
        byebye.clear();
        byebye.insert(-1);

        maxi = -1, index = 0;

        for (int i = 1; i <= n; i++)
        {
            int key = i;
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.count(-1))
            {
                // cout << i << endl;
                continue;
            }

            if ((int)neighbors.size() >= maxi)
            {

                maxi = neighbors.size();
                index = i;
            }
        }

        unordered_set<int> &byebye2 = adj[index];
        // cout << index << endl;
        for (auto a : byebye2)
        {
            int currele = a;
            adj[currele].erase(index);
        }
        byebye2.clear();
        byebye2.insert(-1);
        int res = 0;
        unordered_set<int> selected;
        for (int i = 1; i <= n; i++)
        {
            unordered_set<int> &neighbors = adj[i];
            if (neighbors.count(-1) || selected.count(i))
                continue;
            selected.insert(i);
            for (auto a : neighbors)
            {
                selected.insert(a);
            }
            res++;
        }
        cout << res << endl;
    }
    return 0;
}