ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

long long int func(int r1,int r2,vector<int>v,vector<int>dummy,long long int sum)
{
    vector<int>temp;
    for(int i=r1-1;i<r2;i++)
    {
        temp.push_back(v[i]);
    }
    sort(temp.begin(),temp.end());
    sort(dummy.begin(),dummy.end());
    int left=temp.size()-1,right=0;
    while (left>=0 && right<dummy.size())
    {
        if(dummy[right]<temp[left])
        {
            sum+=dummy[right];
            sum-=temp[left];
        }
        right++;
        left--;
    }
   // cout<<"d_sum=="<<sum<<endl;
    return sum;


}
int main()
{
    int tc;cin>>tc;
     for(int ii=1;ii<=tc;ii++)
    {
        int n,r1,r2;cin>>n>>r1>>r2;
        vector<int>v;
        long long int sum=0;
        for(int i=0;i<n;i++)
        {
            int x;cin>>x;
            v.push_back(x);
            if(i>=r1-1 && i<=r2-1)
            {
                sum+=v[i];
            }
        }
        if(ii==80)
        {
            for(int i=0;i<n;i++) cout<<v[i]<<" ";
            cout<<endl;
            return 0;
        }
        vector<int>dummy;
         for(int i=0;i<r1-1;i++)
         {
            dummy.push_back(v[i]);
         }

        long long res=func(r1,r2,v,dummy,sum);
         sum=min(sum,res);
         dummy.clear();
        for(int i=r2;i<n;i++)
        {
            dummy.push_back(v[i]);
        }

        res=func(r1,r2,v,dummy,sum);
        sum=min(sum,res);
        cout<<sum<<endl;

    }
}


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

long long int func(int r1,int r2,vector<int>v,vector<int>dummy,long long int sum)
{
    vector<int>temp;
    for(int i=r1-1;i<r2;i++)
    {
        temp.push_back(v[i]);
    }
    sort(temp.begin(),temp.end());
    sort(dummy.begin(),dummy.end());
   // for(int i=0;i<temp.size();i++) cout<<temp[i]<<" ";cout<<endl;
   // for(int i=0;i<dummy.size();i++) cout<<dummy[i]<<" ";cout<<endl;
    int left=temp.size()-1,right=0;
    while (left>=0 && right<dummy.size())
    {
        if(dummy[right]<temp[left])
        {
            sum+=dummy[right];
            sum-=temp[left];
        }
        right++;
        left--;
    }
   // cout<<"d_sum=="<<sum<<endl;
    return sum;


}
int main()
{
    int tc;cin>>tc;
     for(int ii=1;ii<=tc;ii++)
    {
        int n,r1,r2;cin>>n>>r1>>r2;
        vector<int>v;
        long long int sum=0,sum1=0;
        for(int i=0;i<n;i++)
        {
            int x;cin>>x;
            v.push_back(x);
            if(i>=r1-1 && i<r2)
            {
                sum+=v[i];
            }
        }
        sum1=sum;
        vector<int>dummy;
         for(int i=0;i<r1-1;i++)
         {
            dummy.push_back(v[i]);
         }

        long long res=func(r1,r2,v,dummy,sum);
         sum=min(sum,res);
         dummy.clear();
        for(int i=r2;i<n;i++)
        {
            dummy.push_back(v[i]);
        }

        res=func(r1,r2,v,dummy,sum1);
        sum1=min(sum1,res);
        cout<<min(sum,sum1)<<endl;

    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>



using namespace std;

#define LL long long 

 int  main()

{

     long long t;cin>>t;

    while(t--)

    {

         long long n,l,r;

        cin>>n>>l>>r;

        vector<int>a(n);

        vector<int>b;

        vector<int>c;

        for( long long i=0;i<n;i++)

        {

            cin>>a[i];

        }

        l--,r--;

        for( long long i=0;i<=r;i++)

        {

            b.push_back(a[i]);

        }

        for( long long i=l;i<n;i++)

        {

            c.push_back(a[i]);

        }

        sort(b.begin(),b.end());

        sort(c.begin(),c.end());

         long long sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0);

         long long sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0);

        cout<<min(sum1,sum2)<<endl;



        



    }

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;
#define LL long long 
 int  main()
{
     long long t;
     cin>>t;
    while(t--)
    {
         long long n,l,r;
        cin>>n>>l>>r;
        vector<long long >a(n);
        vector<long long >b;
        vector<long long >c;
        for( long long i=0;i<n;i++)
        {
            cin>>a[i];
        }
        l--,r--;
        for( long long i=0;i<=r;i++)
        {
            b.push_back(a[i]);
        }
        for( long long i=l;i<n;i++)
        {
            c.push_back(a[i]);
        }
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
         long long sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0LL);
         long long sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0LL);
        cout<<min(sum1,sum2)<<endl;

        

    }
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>

using namespace std;
#define LL long long 
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>a(n);
        vector<int>b;
        vector<int>c;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        l--,r--;
        for(int i=0;i<=r;i++)
        {
            b.push_back(a[i]);
        }
        for(int i=l;i<n;i++)
        {
            c.push_back(a[i]);
        }
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
        int sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0);
        int sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0);
        cout<<min(sum1,sum2)<<endl;

        

    }
}

Submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>



using namespace std;

#define LL long long 

 int  main()

{

     long long t;cin>>t;

    while(t--)

    {

         long long n,l,r;

        cin>>n>>l>>r;

        vector<int>a(n);

        vector<int>b;

        vector<int>c;

        for( long long i=0;i<n;i++)

        {

            cin>>a[i];

        }

        l--,r--;

        for( long long i=0;i<=r;i++)

        {

            b.push_back(a[i]);

        }

        for( long long i=l;i<n;i++)

        {

            c.push_back(a[i]);

        }

        sort(b.begin(),b.end());

        sort(c.begin(),c.end());

         long long sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0);

         long long sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0);

        cout<<min(sum1,sum2)<<endl;



        



    }

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>

using namespace std;
#define LL long long 
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>a(n);
        vector<int>b;
        vector<int>c;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        l--,r--;
        for(int i=0;i<=r;i++)
        {
            b.push_back(a[i]);
        }
        for(int i=l;i<n;i++)
        {
            c.push_back(a[i]);
        }
        sort(b.begin(),b.end());
        sort(c.begin(),c.end());
        int sum1 = accumulate(b.begin(),b.begin()+int(r-l+1),0);
        int sum2 = accumulate(c.begin(),c.begin()+int(r-l+1),0);
        cout<<min(sum1,sum2)<<endl;

        

    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n, k) for (int i = k; i < n + k; i++)
#define all(v) v.begin(), v.end()
#define space << " " 
#define int long long
#define M (998244353) // 1000000007
#define take(n) ll n; cin >> n;
#define takean(a, n, k) ll a[n + k] ={}; forn(i, n, k) cin >> a[i];
#define yes cout << "YES" << endl; return;
#define no cout << "NO" << endl; return;
#define ll long long
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
void solve()
{
 take(n);
 take(k);
 vector<int>a(n);
 map<int,int>mpp;
 for(int i=0;i<n;++i){
    cin>>a[i];
    mpp[a[i]]++;
 }
 vector<int>v;
 for(auto i:mpp){
    v.push_back(i.second);
 }
 sort(v.begin(),v.end());
//  for(auto i:v){
//     cout<<i<<' ';
//  }
//  cout<<endl;
 int m=1;
 for(int i=0;i<v.size()-1;++i){
    if(k==0){
        m=v.size()-i;
        break;
    }
    k=k-min(k,v[i]);

 }
 cout<<m<<endl;


//  for(auto i:mpp){
//     cout<<i.first<<' '<<i.second<<endl;
//  }


}
signed main()
{
int tc = 1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> tc;
while (tc-- > 0)
{
solve();
}
return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n, k) for (int i = k; i < n + k; i++)
#define all(v) v.begin(), v.end()
#define space << " " 
#define int long long
#define M (998244353) // 1000000007
#define take(n) ll n; cin >> n;
#define takean(a, n, k) ll a[n + k] ={}; forn(i, n, k) cin >> a[i];
#define yes cout << "YES" << endl; return;
#define no cout << "NO" << endl; return;
#define ll long long
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
void solve()
{
 take(n);
 take(k);
 vector<int>a(n);
 map<int,int>mpp;
 for(int i=0;i<n;++i){
    cin>>a[i];
    mpp[a[i]]++;
 }
 vector<int>v;
 for(auto i:mpp){
    v.push_back(i.second);
 }
 sort(v.begin(),v.end());
//  for(auto i:v){
//     cout<<i<<' ';
//  }
//  cout<<endl;
 int m=1;
 for(int i=0;i<v.size()-1;++i){
    if(k==0){
        m=v.size()-i;
        break;
    }
    k=k-min(k,v[i]);

 }
 cout<<m<<endl;


//  for(auto i:mpp){
//     cout<<i.first<<' '<<i.second<<endl;
//  }


}
signed main()
{
int tc = 1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> tc;
while (tc-- > 0)
{
solve();
}
return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n, k) for (int i = k; i < n + k; i++)
#define all(v) v.begin(), v.end()
#define space << " " 
#define int long long
#define M (998244353) // 1000000007
#define take(n) ll n; cin >> n;
#define takean(a, n, k) ll a[n + k] ={}; forn(i, n, k) cin >> a[i];
#define yes cout << "YES" << endl; return;
#define no cout << "NO" << endl; return;
#define ll long long
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
void solve()
{
 take(n);
 take(k);
 vector<int>a(n);
 map<int,int>mpp;
 for(int i=0;i<n;++i){
    cin>>a[i];
    mpp[a[i]]++;
 }
 vector<int>v;
 for(auto i:mpp){
    v.push_back(i.second);
 }
 sort(v.begin(),v.end());
//  for(auto i:v){
//     cout<<i<<' ';
//  }
//  cout<<endl;
 int m=1;
 for(int i=0;i<v.size()-1;++i){
    if(k==0){
        m=v.size()-i;
        break;
    }
    if(k<v[i]){
        m++;
    }
    k=k-min(k,v[i]);

 }
 cout<<m<<endl;


//  for(auto i:mpp){
//     cout<<i.first<<' '<<i.second<<endl;
//  }


}
signed main()
{
int tc = 1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> tc;
while (tc-- > 0)
{
solve();
}
return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n, k) for (int i = k; i < n + k; i++)
#define all(v) v.begin(), v.end()
#define space << " " 
#define int long long
#define M (998244353) // 1000000007
#define take(n) ll n; cin >> n;
#define takean(a, n, k) ll a[n + k] ={}; forn(i, n, k) cin >> a[i];
#define yes cout << "YES" << endl; return;
#define no cout << "NO" << endl; return;
#define ll long long
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
void solve()
{
 take(n);
 take(k);
 vector<int>a(n);
 map<int,int>mpp;
 for(int i=0;i<n;++i){
    cin>>a[i];
    mpp[a[i]]++;
 }
 vector<int>v;
 for(auto i:mpp){
    v.push_back(i.second);
 }
 sort(v.begin(),v.end());
//  for(auto i:v){
//     cout<<i<<' ';
//  }
//  cout<<endl;
 int m=1;
 for(int i=0;i<v.size()-1;++i){
    if(k==0){
        m=v.size()-i;
        break;
    }
    if(k<v[i]){
        m++;
    }
    k=k-min(k,v[i]);

 }
 cout<<m<<endl;


//  for(auto i:mpp){
//     cout<<i.first<<' '<<i.second<<endl;
//  }


}
signed main()
{
int tc = 1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> tc;
while (tc-- > 0)
{
solve();
}
return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n, k) for (int i = k; i < n + k; i++)
#define all(v) v.begin(), v.end()
#define space << " " 
#define int long long
#define M (998244353) // 1000000007
#define take(n) ll n; cin >> n;
#define takean(a, n, k) ll a[n + k] ={}; forn(i, n, k) cin >> a[i];
#define yes cout << "YES" << endl; return;
#define no cout << "NO" << endl; return;
#define ll long long
#define vi vector<long long int>
#define vvi vector<vector<long long int>>
bool isPrime(int n)
{
if (n <= 1)
return false;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
return false;
}
return true;
}
void solve()
{
 take(n);
 take(k);
 vector<int>a(n);
 map<int,int>mpp;
 for(int i=0;i<n;++i){
    cin>>a[i];
    mpp[a[i]]++;
 }
 vector<int>v;
 for(auto i:mpp){
    v.push_back(i.second);
 }
 sort(v.begin(),v.end());
//  for(auto i:v){
//     cout<<i<<' ';
//  }
//  cout<<endl;
 int m=1;
 for(int i=0;i<v.size()-1;++i){
    if(k==0){
        m=v.size()-i;
        break;
    }
    if(k>=v[i]){
        k=k-v[i];
    }
    else{
        m=v.size()-i;
        break;
    }

 }
 cout<<m<<endl;


//  for(auto i:mpp){
//     cout<<i.first<<' '<<i.second<<endl;
//  }


}
signed main()
{
int tc = 1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> tc;
while (tc-- > 0)
{
solve();
}
return 0;
}
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;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
int deleteOneVertex(vector<int> &indeg,vector<int> vt[]){
    // cout<<"h"<<endl;
    int n = indeg.size();
    pp p = {-1,-1};
    int vertex = -1;
    for(int i=1;i<n;i++){
        // cout<<i<<"*"<<indeg[i]<<endl;
        if(indeg[i] >= p.first) {
            int maxi = -1;
            for(auto it:vt[i]) maxi = max(indeg[it],maxi);
            if(indeg[i] > p.first || maxi < p.second) vertex = i;
            if(maxi < p.second) p.second = maxi;
            p.first = indeg[i];
        }
    }
    // debug(10);
    // cout<<"hh"<<" "<<vertex<<" "<<p.first<<endl;
    for(auto it:vt[vertex]) indeg[it]--;
    indeg[vertex] = 0;
    return p.first;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    // debug(1);
    // cout<<"before"<<endl;
    int a = deleteOneVertex(indeg,vt);
    int b = deleteOneVertex(indeg,vt);
    if(b == 1) cout<< a <<endl;
    else cout<<a + b - 1<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}



Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    int res = 0;
    for(int i=1;i<=n;i++){
        int temp = indeg[i];
        for(auto it:vt[i]) indeg[it]--;
        indeg[i] = 0;
        int maxi = *max_element(indeg.begin(),indeg.end());
        res = max(res, temp + maxi-1);
        indeg[i] = temp;
        for(auto it:vt[i]) indeg[it]++;
    }
    cout<<res<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}
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;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
int deleteOneVertex(vector<int> &indeg,vector<int> vt[]){
    // cout<<"h"<<endl;
    int n = indeg.size();
    pp p = {-1,-1};
    int vertex = -1;
    for(int i=1;i<n;i++){
        // cout<<i<<"*"<<indeg[i]<<endl;
        if(indeg[i] >= p.first) {
            int maxi = -1;
            for(auto it:vt[i]) maxi = max(indeg[it],maxi);
            if(indeg[i] > p.first || maxi < p.second) vertex = i;
            if(maxi < p.second) p.second = maxi;
            p.first = indeg[i];
        }
    }
    // debug(10);
    // cout<<"hh"<<" "<<vertex<<endl;
    for(auto it:vt[vertex]) indeg[it]--;
    indeg[vertex] = 0;
    return p.first;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    // debug(1);
    // cout<<"before"<<endl;
    int a = deleteOneVertex(indeg,vt);
    int b = deleteOneVertex(indeg,vt);
    cout<<a + b - 1<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}



Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
int deleteOneVertex(vector<int> &indeg,vector<int> vt[]){
    // cout<<"h"<<endl;
    int n = indeg.size();
    pp p = {-1,-1};
    int vertex = -1;
    for(int i=1;i<n;i++){
        // cout<<i<<"*"<<indeg[i]<<endl;
        if(indeg[i] >= p.first) {
            int maxi = -1;
            for(auto it:vt[i]) maxi = max(indeg[it],maxi);
            if(indeg[i] > p.first || maxi < p.second) vertex = i;
            if(maxi < p.second) p.second = maxi;
            p.first = indeg[i];
        }
    }
    // debug(10);
    // cout<<"hh"<<" "<<vertex<<endl;
    for(auto it:vt[vertex]) indeg[it]--;
    indeg[vertex] = 0;
    return p.first;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    // debug(1);
    // cout<<"before"<<endl;
    int a = deleteOneVertex(indeg,vt);
    int b = deleteOneVertex(indeg,vt);
    if(b == 1) cout<< a + b<<endl;
    else cout<<a + b - 1<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}
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;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
int deleteOneVertex(vector<int> &indeg,vector<int> vt[]){
    // cout<<"h"<<endl;
    int n = indeg.size();
    pp p = {-1,-1};
    int vertex = -1;
    for(int i=1;i<n;i++){
        // cout<<i<<"*"<<indeg[i]<<endl;
        if(indeg[i] >= p.first) {
            int maxi = -1;
            for(auto it:vt[i]) maxi = max(indeg[it],maxi);
            if(indeg[i] > p.first || maxi < p.second) vertex = i;
            if(maxi < p.second) p.second = maxi;
            p.first = indeg[i];
        }
    }
    // debug(10);
    // cout<<"hh"<<" "<<vertex<<endl;
    for(auto it:vt[vertex]) indeg[it]--;
    indeg[vertex] = 0;
    return p.first;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    // debug(1);
    // cout<<"before"<<endl;
    int a = deleteOneVertex(indeg,vt);
    int b = deleteOneVertex(indeg,vt);
    if(b == 1) cout<< a + b<<endl;
    else cout<<a + b - 1<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}



Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
int deleteOneVertex(vector<int> &indeg,vector<int> vt[]){
    // cout<<"h"<<endl;
    int n = indeg.size();
    pp p = {-1,-1};
    int vertex = -1;
    for(int i=1;i<n;i++){
        // cout<<i<<"*"<<indeg[i]<<endl;
        if(indeg[i] >= p.first) {
            int maxi = -1;
            for(auto it:vt[i]) maxi = max(indeg[it],maxi);
            if(indeg[i] > p.first || maxi < p.second) vertex = i;
            if(maxi < p.second) p.second = maxi;
            p.first = indeg[i];
        }
    }
    // debug(10);
    // cout<<"hh"<<" "<<vertex<<" "<<p.first<<endl;
    for(auto it:vt[vertex]) indeg[it]--;
    indeg[vertex] = 0;
    return p.first;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    // debug(1);
    // cout<<"before"<<endl;
    int a = deleteOneVertex(indeg,vt);
    int b = deleteOneVertex(indeg,vt);
    if(b == 1) cout<< a <<endl;
    else cout<<a + b - 1<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < ll, ll > pp;
const int N = 1e5+2;
void debug(int cnt){
    cout<<"debug "<<cnt<<endl;
}
int deleteOneVertex(vector<int> &indeg,vector<int> vt[]){
    // cout<<"h"<<endl;
    int n = indeg.size();
    pp p = {-1,-1};
    int vertex = -1;
    for(int i=1;i<n;i++){
        // cout<<i<<"*"<<indeg[i]<<endl;
        if(indeg[i] >= p.first) {
            int maxi = -1;
            for(auto it:vt[i]) maxi = max(indeg[it],maxi);
            if(indeg[i] > p.first || maxi < p.second) vertex = i;
            if(maxi < p.second) p.second = maxi;
            p.first = indeg[i];
        }
    }
    // debug(10);
    // cout<<"hh"<<" "<<vertex<<endl;
    for(auto it:vt[vertex]) indeg[it]--;
    indeg[vertex] = 0;
    return p.first;
}
void solve() {
    int n;cin>>n;
    vector<int> indeg(n+1,0);
    vector<int> vt[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        vt[u].push_back(v);
        vt[v].push_back(u);
        indeg[u]++;
        indeg[v]++;
    }
    // debug(1);
    // cout<<"before"<<endl;
    int a = deleteOneVertex(indeg,vt);
    int b = deleteOneVertex(indeg,vt);
    cout<<a + b - 1<<endl;
}
int main() {
    int t;cin>>t;
    while(t--) solve();
}