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

Previous submission (verdict: Wrong answer on test 2):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h> 
#include <cmath>
using namespace std; 
#include <bits/stdc++.h> 
using namespace std; 
using ll = long long int;
 
 int largest(vector<int>& arr) {
         int max = arr[0];

    
    for (int i = 1; i < arr.size(); i++)
        if (arr[i] > arr[max])
            max = i;

    return max;
}
 
int main()
{  int n;
   cin>>n;
   vector <int> v;
   
   int a,m,b;
    
    for(int i=0;i<n;i++ ){
        
        cin>>m;
        vector <int> vec[m];
        for(int j=0;j<m;j++){
            v.push_back(0);
            
        }
        
        for(int j=0;j<m-1;j++){
            cin>>a>>b;
            v[a-1]=v[a-1]+1;
            v[b-1]=v[b-1]+1;
            vec[a-1].push_back(b-1);
            vec[b-1].push_back(a-1);
        }
        int p= largest(v);
        
        int sum=v[p];
        for(int j=0;j<vec[p].size();j++){
            v[vec[p][j]]=v[vec[p][j]]-1;
            
        } 
        
        v.erase(v.begin() + p);
        int q=largest(v);
        
        sum=sum+v[q]-1; 
        cout<<sum<<'\n';
        v.clear();
        
        }
    
     
    
    
    return 0;
}

Submission (verdict: Wrong answer on test 2):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h> 
#include <cmath>
using namespace std; 
#include <bits/stdc++.h> 
using namespace std; 
using ll = long long int;
 
 int largest(vector<int>& arr) {
         int max = 0;

    
    for (int i = 1; i < arr.size(); i++)
        if (arr[i] > arr[max])
            max = i;

    return max;
}
 
int main()
{  int n;
   cin>>n;
   vector <int> v;
   
   int a,m,b;
    
    for(int i=0;i<n;i++ ){
        
        cin>>m;
        vector <int> vec[m];
        for(int j=0;j<m;j++){
            v.push_back(0);
            
        }
        
        for(int j=0;j<m-1;j++){
            cin>>a>>b;
            v[a-1]=v[a-1]+1;
            v[b-1]=v[b-1]+1;
            vec[a-1].push_back(b-1);
            vec[b-1].push_back(a-1);
        }
        
        int p= largest(v);
        
        int sum=v[p];
        
        for(int j=0;j<vec[p].size();j++){
            v[vec[p][j]]=v[vec[p][j]]-1;
            
        } 
        
        v.erase(v.begin() + p);
        int q=largest(v);
        
        sum=sum+v[q]-1; 
        cout<<sum<<'\n';
        v.clear();
        
        }
    
     
    
    
    return 0;
}