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

Previous submission (verdict: Time limit exceeded on test 10):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, n) for (int i = x; i < n; i++)
#define sortv(v) sort(v.begin(), v.end())
#define sortrv(v) sort(v.rbegin(), v.rend())
#define MOD 1000000000
#define pb push_back

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

void solve() {
    int n; cin >> n;
    vector<pair<int, int>> edges(n - 1);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[i] = make_pair(u, v);
    }
    
    vector<vector<int>> adj(n);
    for (auto& edge : edges) {
        adj[edge.first].push_back(edge.second);
        adj[edge.second].push_back(edge.first);
    }
    
    vector<int> deg(n, 0);
    rep(i,0,n) {
        deg[i] = adj[i].size();
    }
    
    vector<int> node;
    rep(i,0,n) {
        node.push_back(i);
    }
    
    sort(node.begin(), node.end(), [&](int a, int b) { return deg[a] > deg[b]; });
    auto cc = [&](int v1, int v2) {
        vector<bool> rem(n, false);
        rem[v1] = rem[v2] = true;
        int curr = 0;
        vector<bool> vis(n, false);
        function<void(int)> dfs1 = [&](int v) {
            vis[v] = true;
            for (int u : adj[v]) {
                if (!vis[u] && !rem[u]) {
                    dfs1(u);
                }
            }
        };
        
        rep(i,0,n) {
            if (!vis[i] && !rem[i]) {
                dfs1(i);
                curr++;
            }
        }
        
        return curr;
    };
    int res = 0;
    int K = min(12*1LL, n);
    rep(i,0,K) {
        rep(j,i+1,K) {
            res = max(res, cc(node[i], node[j]));
        }
    }
    
    cout << res << endl;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Uncomment the next line for file input/output
    // setIO("shell");
    int tc = 1;
    cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 12):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, n) for (int i = x; i < n; i++)
#define sortv(v) sort(v.begin(), v.end())
#define sortrv(v) sort(v.rbegin(), v.rend())
#define MOD 1000000000
#define pb push_back

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

void solve() {
    int n; cin >> n;
    vector<pair<int, int>> edges(n - 1);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[i] = make_pair(u, v);
    }
    
    vector<vector<int>> adj(n);
    for (auto& edge : edges) {
        adj[edge.first].push_back(edge.second);
        adj[edge.second].push_back(edge.first);
    }
    
    vector<int> deg(n, 0);
    rep(i,0,n) {
        deg[i] = adj[i].size();
    }
    
    vector<int> node;
    rep(i,0,n) {
        node.push_back(i);
    }
    
    sort(node.begin(), node.end(), [&](int a, int b) { return deg[a] > deg[b]; });
    auto cc = [&](int v1, int v2) {
        vector<bool> rem(n, false);
        rem[v1] = rem[v2] = true;
        int curr = 0;
        vector<bool> vis(n, false);
        function<void(int)> dfs1 = [&](int v) {
            vis[v] = true;
            for (int u : adj[v]) {
                if (!vis[u] && !rem[u]) {
                    dfs1(u);
                }
            }
        };
        
        rep(i,0,n) {
            if (!vis[i] && !rem[i]) {
                dfs1(i);
                curr++;
            }
        }
        
        return curr;
    };
    int res = 0;
    int K = min(10*1LL, n);
    rep(i,0,K) {
        rep(j,i+1,K) {
            res = max(res, cc(node[i], node[j]));
        }
    }
    
    cout << res << endl;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Uncomment the next line for file input/output
    // setIO("shell");
    int tc = 1;
    cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}