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

Previous submission (verdict: Wrong answer on test 1):
#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 dp[MAXN][2];

void dfs(int v, int p) {
    int c = 0;
    int mx1 = -1e9;
    int mx2 = -1e9;
    for (int u : g[v]) {
        if (u != p) {
            dfs(u, v);
            c++;
            if (dp[v][0] >= mx2) {
                mx1 = mx2;
                mx2 = dp[v][0];
            } else if (dp[v][0] >= mx1) {
                mx1 = dp[v][0];
            }
            dp[v][1] = max(dp[v][1], dp[u][1]);
            dp[v][0] = max(dp[v][0], dp[u][0]);
        }
    }
    dp[v][0] = max(dp[v][0], c + (p != -1));
    dp[v][1] = max(dp[v][1], mx1 + mx2);
    dp[v][1] = max(dp[v][1], c + (p != -1) + mx2 - 1);
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        g[i].clear();
        dp[i][0] = dp[i][1] = 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);
    }
    dfs(0, -1);
    cout << dp[0][1] << '\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 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;
}