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

Previous submission (verdict: Wrong answer on test 4):
// || =================================================================== ||
// ||                                                                     ||
// ||                   Reach Expert by May 2025                          ||
// ||                                                                     ||
// || =================================================================== ||
#include <bits/stdc++.h>
#define int long long
#define endl "\n";
#define all(a) a.begin(), a.end()     
using namespace std;
long long mod_exp(long long base, long long exp, long long mod) {
    long long result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;     
        }
        base = (base * base) % mod; 
        exp /= 2; 
    }
    return result;
}
void dfs(int cur, vector<set<int>> &graph, vector<int> & vis){
    if(vis[cur]) return;
    vis[cur] = 1;
    for(auto v : graph[cur]){
        if(!vis[v]){
            dfs(v, graph, vis);
        }
    }
}
void solve() {
    int n;
    cin >> n;
    vector<set<int>> graph(n + 1);
    vector<pair<int,int>> edges;
    for(int i = 1; i <= n - 1; i++){
        int u, v;
        cin >> u >> v;
        edges.push_back({u, v});
        graph[u].insert(v);
        graph[v].insert(u);
    }   
    vector<pair<int,int>> vec;
    for(int i = 1; i <= n; i++){
        vec.push_back({(int)graph[i].size(), i});
    }
    sort(all(vec));
    reverse(all(vec));
    // for(auto p : vec){
    //     cout << p.first << " : " << p.second << endl;
    // }
    int ans = 0;
    for(int i = 0 + 1; i < n; i++){
        int v = vec[0].second;
        int u = vec[i].second;
        if(graph[v].count(u)){
            ans = max(vec[0].first + vec[i].first - 2, ans);
        }else{
            ans = max(vec[0].first + vec[i].first - 1, ans);
            break;
        }
    }
    
    cout << ans << endl;

   
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin);  
        freopen("output.txt", "w", stdout); 
    #endif  
    int t;
    cin >> t;
    while(t--)
        solve();
   
} 

Submission (verdict: Wrong answer on test 4):
// || =================================================================== ||
// ||                                                                     ||
// ||                   Reach Expert by May 2025                          ||
// ||                                                                     ||
// || =================================================================== ||
#include <bits/stdc++.h>
#define int long long
#define endl "\n";
#define all(a) a.begin(), a.end()     
using namespace std;
long long mod_exp(long long base, long long exp, long long mod) {
    long long result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;     
        }
        base = (base * base) % mod; 
        exp /= 2; 
    }
    return result;
}
void dfs(int cur, vector<set<int>> &graph, vector<int> & vis){
    if(vis[cur]) return;
    vis[cur] = 1;
    for(auto v : graph[cur]){
        if(!vis[v]){
            dfs(v, graph, vis);
        }
    }
}
void solve() {
    int n;
    cin >> n;
    vector<set<int>> graph(n + 1);
    vector<pair<int,int>> edges;
    for(int i = 1; i <= n - 1; i++){
        int u, v;
        cin >> u >> v;
        edges.push_back({u, v});
        graph[u].insert(v);
        graph[v].insert(u);
    }   
    vector<pair<int,int>> vec;
    for(int i = 1; i <= n; i++){
        vec.push_back({(int)graph[i].size(), i});
    }
    sort(all(vec));
    reverse(all(vec));
    // for(auto p : vec){
    //     cout << p.first << " : " << p.second << endl;
    // }
    int ans = 0;
    for(int i = 0 + 1; i < n; i++){
        int v = vec[0].second;
        int u = vec[i].second;
        if(graph[v].count(u)){
            ans = max(vec[0].first + vec[i].first - 2, ans);
        }else{
            ans = max(vec[0].first + vec[i].first - 1, ans);
            break;
        }
    }
    for(auto p : edges){
        int u = p.first;
        int v = p.second;
        ans = max(ans, (int)(graph[u].size() + graph[v].size() - 2));
    }
    cout << ans << endl;

   
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin);  
        freopen("output.txt", "w", stdout); 
    #endif  
    int t;
    cin >> t;
    while(t--)
        solve();
   
}