Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

using ll = long long;
using str = string;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using si = set<int>;

#define sz (int)(x).size()
#define pb push_back
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define del(x, i) erase(begin(x) + i)
#define rem(x, i) erase(begin(x), begin(x) + i)

#define mp make_pair
#define sec second
#define fir first

#define ins insert
#define ez erase
#define cnt count

#define MOD 1e9 + 7
#define MAX_INT 1e18 * 9

#define possibilities(x) while(next_permutation(all(x)))

#define Trav(a, x) for (auto &a : x)
#define For(i, a, b) for (int i = (a); i < (b); ++i)

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> degree(n);
    For(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        degree[x]++, degree[y]++;
        adj[x].pb(y), adj[y].pb(x);
    }
    if(n <= 2) {
        cout << 0 << endl;
        return;
    }
    int res = 0;

    int rm = 0;
    for(int i = 0; i < n; i++) if(degree[i] > degree[rm]) rm = i;
    res += degree[rm];
    for(int x: adj[rm]) degree[x]--;
    degree[rm] = -1;

    rm = 0;
    For(i, 0, n) if(degree[i] > degree[rm]) rm = i;
    res += degree[rm];
        
    cout << res - 1 << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Compilation error):
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using str = string;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using si = set<int>;

#define sz (int)(x).size()
#define pb push_back
#define all(x) begin(x), end(x)
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define del(x, i) erase(begin(x) + i)
#define rem(x, i) erase(begin(x), begin(x) + i)

#define mp make_pair
#define sec second
#define fir first

#define ins insert
#define ez erase
#define cnt count

#define MOD 1e9 + 7
#define MAX_INT 1e18 * 9

#define possibilities(x) while(next_permutation(all(x)))

#define Trav(a, x) for (auto &a : x)
#define For(i, a, b) for (int i = (a); i < (b); ++i)

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> adj(n);
    vector<int> degree(n);
    For(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        degree[x]++, degree[y]++;
        adj[x].pb(y), adj[y].pb(x);
    }
    if(n <= 2) {
        cout << 0 << endl;
        return;
    }
    int res = 1;
    set<pair<int, int>> ms;

    For(i, 0, n) {
        ms.ins({degree[i], i});
    }

    For(i, 0, 2) {
        set<pair<int, int>> temp(ms);
        int curr = 0;
        int rm = (temp.rbegin() - i)->second;
        curr += degree[rm];
        temp.erase({degree[rm], rm});
        for(auto &x: adj[rm]) {
            temp.erase({degree[x], x});
            temp.ins({degree[x] - 1, x});
        }
        rm = temp.rbegin()->second;
        curr += degree[rm];
        res = max(res, curr - 1);
    }
        
    cout << res << endl;
}

int main() {
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}