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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    const int K = 200; // 取前200个顶点检查
    while (t--) {
        int n;
        cin >> n;
        if (n == 2) {
            cout << 0 << '\n';
            int u, v;
            cin >> u >> v;
            continue;
        }
        vector<unordered_set<int>> adj(n + 1);
        vector<int> degrees(n + 1, 0);
        vector<pair<int, int>> edges;
        for (int i = 0; i < n - 1; ++i) {
            int u, v;
            cin >> u >> v;
            adj[u].insert(v);
            adj[v].insert(u);
            degrees[u]++;
            degrees[v]++;
            edges.emplace_back(u, v);
        }
        // 计算相邻顶点对的最大度数之和-1
        int max_adj = 0;
        for (auto &[u, v] : edges) {
            int current = degrees[u] + degrees[v] - 1;
            if (current > max_adj) {
                max_adj = current;
            }
        }
        // 按度数降序排列顶点
        vector<int> nodes(n);
        iota(nodes.begin(), nodes.end(), 1);
        sort(nodes.begin(), nodes.end(), [&](int a, int b) {
            return degrees[a] > degrees[b];
        });
        // 检查前K个顶点中的不相邻对
        int m = min(n, K);
        int max_non_adj = 0;
        for (int i = 0; i < m; ++i) {
            int u = nodes[i];
            for (int j = i + 1; j < m; ++j) {
                int v = nodes[j];
                if (adj[u].find(v) == adj[u].end()) {
                    int current = degrees[u] + degrees[v];
                    if (current > max_non_adj) {
                        max_non_adj = current;
                    }
                }
            }
        }
        // 计算最大值并输出结果
        int max_value = max(max_adj, max_non_adj);
        cout << max_value - 1 << '\n';
    }
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    const int K = 200; // 取前200个顶点检查
    while (t--) {
        int n;
        cin >> n;
        if (n == 2) {
            cout << 0 << '\n';
            int u, v;
            cin >> u >> v;
            continue;
        }
        vector<unordered_set<int>> adj(n + 1);
        vector<int> degrees(n + 1, 0);
        vector<pair<int, int>> edges;
        for (int i = 0; i < n - 1; ++i) {
            int u, v;
            cin >> u >> v;
            adj[u].insert(v);
            adj[v].insert(u);
            degrees[u]++;
            degrees[v]++;
            edges.emplace_back(u, v);
        }
        int max_adj = 0;
        for (auto &e : edges) {
            int u = e.first, v = e.second;
            int current = degrees[u] + degrees[v] - 2;
            if (current > max_adj) {
                max_adj = current;
            }
        }
        vector<int> nodes(n);
        iota(nodes.begin(), nodes.end(), 1);
        sort(nodes.begin(), nodes.end(), [&](int a, int b) {
            return degrees[a] > degrees[b];
        });
        int m = min(n, K);
        int max_non_adj = 0;
        for (int i = 0; i < m; ++i) {
            int u = nodes[i];
            for (int j = i + 1; j < m; ++j) {
                int v = nodes[j];
                if (!adj[u].count(v)) {
                    int current = degrees[u] + degrees[v] - 1;
                    if (current > max_non_adj) {
                        max_non_adj = current;
                    }
                }
            }
        }
        cout << max(max_adj, max_non_adj) << '\n';
    }
    return 0;
}