ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()] << endl;

    }

}













Submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

            else

                ans[i][0] = ans[i - 1][0];

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

            else

                ans[0][i] = ans[0][i - 1];

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        for (vector<int> i : ans)

        {

            for (int j : i)

                cout << j;

            cout << '\n';

        }

        cout << ans[a.size()][b.size()] << endl;

    }

}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 1):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size(), vector<int>(b.size(), 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()];

    }

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


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



using namespace std;



void solve() {

    string s;

    cin>>s;

    int n = s.size();

    for (int i = 0; i < n; i++) {

        int maxi = s[i] - '0';

        int mini = -1;

        int ind = i;

        for (int j = 1; j <= 9 && i + j < n; j++) {

            int num = s[i + j] - '0' - j;

            if (num > maxi) {

                maxi = num;

                ind = i + j;

            } else if (ind != i && maxi == num) {

                maxi = num;

                ind = i + j;

            }

            

            if (mini == -1 || s[mini] > s[i + j])

                mini = i + j;

        }

        if (ind != i) {

            s[ind] = s[mini];

            s[mini] = s[i];

            s[i] = char(maxi + '0');

        }

    }

    cout<<s<<endl;

}



signed main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int ttt = 1;

    cin >> ttt;

    while(ttt--) {

        solve();

    }

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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



using namespace std;



void solve() {

    string s;

    cin>>s;

    int n = s.size();

    for (int i = 0; i < n; i++) {

        int maxi = s[i] - '0';

        int mini = -1;

        int ind = i;

        for (int j = 1; j <= 9 && i + j < n; j++) {

            int num = s[i + j] - '0' - j;

            if (num > maxi) {

                maxi = num;

                ind = i + j;

            } else if (ind != i && maxi == num) {

                maxi = num;

                ind = i + j;

            }

            

            if (mini == -1 || s[mini] > s[i + j])

                mini = i + j;

        }

        if (ind != i) {

            s[ind] = s[mini];

            s[mini] = s[i];

            s[i] = char(maxi + '0');

        }

    }

    cout<<s<<endl;

}



signed main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int ttt = 1;

    cin >> ttt;

    while(ttt--) {

        solve();

    }

}

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



using namespace std;



void solve() {

    string s;

    cin>>s;

    int n = s.size();

    for (int i = 0; i < n; i++) {

        int maxi = s[i] - '0';

        int mini = -1;

        int ind = i;

        for (int j = 1; j <= 9 && i + j < n; j++) {

            int num = s[i + j] - '0' - j;

            if (num > maxi) {

                maxi = num;

                ind = i + j;

            } else if (ind != i && maxi == num) {

                maxi = num;

                ind = i + j;

            }

        }

        for (int j = i + 1; j <= ind; j++) {

            if (mini == -1 || s[mini] > s[j])

                mini = j;

        }

        // cout<<ind<<" "<<mini<<endl;

        if (ind != i && s[mini] > s[i]) {

            s[ind] = s[i];

            s[i] = char(maxi + '0');

        }

        else if (ind != i) {

            s[ind] = s[mini];

            s[mini] = s[i];

            s[i] = char(maxi + '0');

        }

    }

    cout<<s<<endl;

}



signed main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int ttt = 1;

    cin >> ttt;

    while(ttt--) {

        solve();

    }

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

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



using namespace std;



void solve() {

    string s;

    cin>>s;

    int n = s.size();

    for (int i = 0; i < n; i++) {

        int maxi = s[i] - '0';

        int mini = -1;

        int ind = i;

        for (int j = 1; j <= 9 && i + j < n; j++) {

            int num = s[i + j] - '0' - j;

            if (num > maxi) {

                maxi = num;

                ind = i + j;

            } else if (ind != i && maxi == num) {

                maxi = num;

                ind = i + j;

            }

        }

        for (int j = i + 1; j <= ind; j++) {

            if (mini == -1 || s[mini] > s[j])

                mini = j;

        }

        // cout<<ind<<" "<<mini<<endl;

        if (ind != i && s[mini] > s[i]) {

            s[ind] = s[i];

            s[i] = char(maxi + '0');

        }

        else if (ind != i) {

            s[ind] = s[mini];

            s[mini] = s[i];

            s[i] = char(maxi + '0');

        }

    }

    cout<<s<<endl;

}



signed main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int ttt = 1;

    cin >> ttt;

    while(ttt--) {

        solve();

    }

}

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



using namespace std;



void solve() {

    string s; cin >> s;

    for (int i = 0; i < s.size(); i++) {

        int best = s[i] - '0', pos = i;

        for (int j = i; j < min(i + 10, (int) s.size()); j++) {

            if (s[j] - '0' - (j - i) > best) {

                best = s[j] - '0' - (j - i);

                pos = j;

            }

        }

        while (pos > i) {

            swap(s[pos], s[pos - 1]);

            pos--;

        }

        s[i] = char(best + '0');

    }

    cout << s;

}



int main() {

    int TESTS = 1; cin >> TESTS;

    while (TESTS --> 0) {

        solve();

        cout << '\n';

    }

    return 0;

}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        int ans = solve(a,b,c,0,0); 
        cout<<ans<<endl;
    }
}

Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return dp[ind1][ind2] = min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        int ans = solve(a,b,c,0,0); 
        cout<<ans<<endl;
    }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return dp[ind1][ind2] = min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        int ans = solve(a,b,c,0,0); 
        cout<<ans<<endl;
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return dp[ind1][ind2] = min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        // int ans = solve(a,b,c,0,0); 
        for(int i=(n);i>=0;i--){
            for(int j=(m);j>=0;j--){
                if(i==n && j==m) continue;
                int op1 = inf;
                int op2 = inf;
                int op3 = inf;
                int op4 = inf;
                if(i<n && a[i] == c[i+j]){
                    op1 = dp[i+1][j];
                }
                if(j<m && b[j] == c[i+j]){
                    op2 = dp[i][j+1];
                }
                if(i<n)op3 = 1 + dp[i+1][j];
                if(j<m)op4 = 1 + dp[i][j+1];
                dp[i][j] = min(op1,min(op2,min(op3,op4)));
            }
        }
        cout<<dp[0][0]<<endl;
        // cout<<ans<<endl;
    }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e5+5
vector<vector<int>> dp;
int solve(string a,string b,string c,int ind1,int ind2){
    // base case
    // cout<<ind1<<" "<<ind2<<endl;
    if(ind1 == a.size() && ind2 == b.size()){
        return 0;
    }
    if(dp[ind1][ind2] != -1){
        return dp[ind1][ind2];
    }
    int op1 = inf;
    int op2 = inf;
    int op3 = inf;
    int op4 = inf;

    if(a[ind1] == c[ind1+ind2] && ind1<a.size()){
        op1 = solve(a,b,c,ind1+1,ind2);
    }
    if(b[ind2] == c[ind1+ind2] && ind2<b.size()){
        op2 = solve(a,b,c,ind1,ind2+1);
    }
    if(ind1<a.size())op3 = 1 + solve(a,b,c,ind1+1,ind2);
    if(ind2<b.size())op4 = 1 + solve(a,b,c,ind1,ind2+1);
    return min({op1,op2,op3,op4});
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        int k = c.size();
        dp = vector<vector<int>>(n+1,vector<int>(m+1,-1));
        dp[n][m] = 0;
        int ans = solve(a,b,c,0,0); 
        cout<<ans<<endl;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--)
  {
   int l,r;
   cin>>l>>r;
   int a=0,b=0,c;
   int k=31;
   if((r-l+1)==3)
   {
	cout<<l<<" "<<l+1<<" "<<r<<endl;
   continue;
   }
   while(k>=0)
   {
      if((r&(1<<k))==(l&(1<<k)))
	  {
		  if(l&(1<<k))
		  {
               a|=(1<<k);
			   b|=(1<<k);
		  } 

          k--;
	  }
	  else
	  {
		     a|=(1<<k);
             break;
	  }
	   
   }
   k--;
   
 while(k>=0)
 {
	if(!(l&(1<<k))){
		while(k>=0)
		{
			if(!(l&(1<<k))) b|=(1<<k);
			k--;
		}
		break;
	}
	 b|=(1<<k);
     k--;
 }

 cout<<a<<" "<<b<<" "<<l<<endl;







    
  }
  return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		int l, r;
		cin >> l >> r;
		int a = 0, b = 0, c;
		int k = 31;

		while (k >= 0)
		{
			if ((r & (1 << k)) == (l & (1 << k)))
			{
				if (l & (1 << k))
				{
					a |= (1 << k);
					b |= (1 << k);
				}

				k--;
			}
			else
			{
				a |= (1 << k);
				break;
			}
		}
		k--;

		while (k >= 0)
		{
			if (!(l & (1 << k)))
			{
				while (k >= 0)
				{
					if (!(l & (1 << k)))
						b |= (1 << k);
					k--;
				}
				break;
			}
			b |= (1 << k);
			k--;
		}
		if (b != l)
			cout << a << " " << b << " " << l << endl;
		else
			cout << a << " " << b << " " << r << endl;
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--)
  {
   int l,r;
   cin>>l>>r;
   int a=0,b=0,c;
   int k=32;
   while(k>=0)
   {
      if((r&(1<<k))==(l&(1<<k)))
	  {
		  if(l&(1<<k))
		  {
               a|=(1<<k);
			   b|=(1<<k);
		  } 

          k--;
	  }
	  else
	  {
		     a|=(1<<k);
             break;
	  }
	   
   }
   k--;
   
 while(k>=0)
 {
	if(!(l&(1<<k))){
		while(k>=0)
		{
			if(!(l&(1<<k))) b|=(1<<k);
			k--;
		}
		break;
	}
	 b|=(1<<k);
     k--;
 }

 cout<<a<<" "<<b<<" "<<l<<endl;







    
  }
  return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--)
  {
   int l,r;
   cin>>l>>r;
   int a=0,b=0,c;
   int k=32;
   while(k>=0)
   {
      if((r&(1<<k))==(l&(1<<k)))
	  {
		  if(l&(1<<k))
		  {
               a|=(1<<k);
			   b|=(1<<k);
		  } 

          k--;
	  }
	  else
	  {
		     a|=(1<<k);
             break;
	  }
	   
   }
   k--;
   
 while(k>=0)
 {
	if(!(l&(1<<k))){
		while(k>=0)
		{
			if(!(l&(1<<k))) b|=(1<<k);
			k--;
		}
		break;
	}
	 b|=(1<<k);
     k--;
 }

 cout<<a<<" "<<b<<" "<<l<<endl;







    
  }
  return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--)
  {
   int l,r;
   cin>>l>>r;
   int a=0,b=0,c;
   int k=31;
   if((r-l+1)==3)
   {
	cout<<l<<" "<<l+1<<" "<<r<<endl;
   continue;
   }
   while(k>=0)
   {
      if((r&(1<<k))==(l&(1<<k)))
	  {
		  if(l&(1<<k))
		  {
               a|=(1<<k);
			   b|=(1<<k);
		  } 

          k--;
	  }
	  else
	  {
		     a|=(1<<k);
             break;
	  }
	   
   }
   k--;
   
 while(k>=0)
 {
	if(!(l&(1<<k))){
		while(k>=0)
		{
			if(!(l&(1<<k))) b|=(1<<k);
			k--;
		}
		break;
	}
	 b|=(1<<k);
     k--;
 }

 cout<<a<<" "<<b<<" "<<l<<endl;







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


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

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<set<int>> adj(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        adj[a].insert(b);
        adj[b].insert(a);
    }

    // Find the vertex with the maximum degree
    int mx = 0, mx_val = 0;
    for (int i = 0; i < n; ++i) {
        if (adj[i].size() > mx_val) {
            mx = i;
            mx_val = adj[i].size();
        }
    }

    // Adjust degrees of vertices adjacent to mx
    vector<int> deg(n);
    for (int i = 0; i < n; ++i) {
        deg[i] = adj[i].size();
    }
    for (int v : adj[mx]) {
        deg[v]--;
    }

    // Find the vertex with the highest adjusted degree
    int mx2 = -1, mx_val_2 = 0;
    for (int i = 0; i < n; ++i) {
        if (i == mx) continue;
        if (deg[i] > mx_val_2) {
            mx2 = i;
            mx_val_2 = deg[i];
        }
    }

    // Calculate the maximum number of connected components
    int result = mx_val + mx_val_2 - 1;
    cout << result << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;

    while (t--)
        solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<set<int>> adj(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        adj[a].insert(b);
        adj[b].insert(a);
    }

    // Find the vertex with the maximum degree
    int mx = 0, mx_val = 0;
    for (int i = 0; i < n; ++i) {
        if (adj[i].size() > mx_val) {
            mx = i;
            mx_val = adj[i].size();
        }
    }

    // Adjust degrees of vertices adjacent to mx
    vector<int> deg(n);
    for (int i = 0; i < n; ++i) {
        deg[i] = adj[i].size();
    }
    for (int v : adj[mx]) {
        deg[v]--;
    }

    // Find the vertex with the highest adjusted degree
    int mx2 = -1, mx_val_2 = 0;
    for (int i = 0; i < n; ++i) {
        if (i == mx) continue;
        if (deg[i] > mx_val_2) {
            mx2 = i;
            mx_val_2 = deg[i];
        }
    }

    // Calculate the maximum number of connected components
    int result = mx_val + mx_val_2 - 1;
    cout << result << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;

    while (t--)
        solve();
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long

using namespace std;

void solve() {
  int n;
  cin >> n;

  vector<set<int>> adj(n);
  for (int i=0; i<n-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    adj[a].insert(b);
    adj[b].insert(a);
  }

  int mx_val=0, mx=0;
  for (int i=0; i<n; ++i) {
    if (adj[i].size() > mx_val) {
      mx=i;
      mx_val=adj[i].size();
    }
  }
  int mx_val_2=0, mx2=0;
  for (int i=0; i<n; ++i) {
    if (i==mx) continue;
    int cnt=adj[i].size()-adj[i].count(mx);
    if (cnt>mx_val_2) {
      mx2=i;
      mx_val_2=cnt;
    }
  }

  cout << mx_val + mx_val_2 - 1 - adj[mx2].count(mx)  << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int t=1;
  cin >> t;

  while (t--)
    solve();
}