ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n);

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

        v[i] = (i % 3);

    }



    if(n % 3 != 0) {

        v[n - 1] = 1;

        v[n - 2] = 0;

    }



    int l = (x - 1 + n) % n;

    int r = (x + 1) % n;



    if(y != l && y != r) {

        if(v[x] == v[y] && v[y] == 1) {

            if(x > y ) swap(x, y);

            if(n % 3 == 2) {

                v[x] = 2;

                v[(x + 1) % n] = 1;

            }

            else {

                v[x] = 3;

                v[(x + 1) % n] = 1;

                if(n % 3 == 1) v[y] = 2;

            }

        }

    }







    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";

}          

int main() {

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

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

}

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n);

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

        v[i] = (i % 3);

    }



    if(n % 3 != 0) {

        v[n - 1] = 1;

        v[n - 2] = 0;

    }



    int l = (x - 1 + n) % n;

    int r = (x + 1) % n;



    if(y != l && y != r) {

        if(v[x] == v[y] && v[y] == 1) {

            if(x > y ) swap(x, y);

            v[x] = 2;

            v[(x + 1) % n] = 1;

            if(n % 3 == 1) v[y] = 2;

        }

    }







    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";

}          

int main() {

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

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

}
Problem: 2049C - MEX Cycle
Language: C++20 (GCC 13-64)


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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 2;

void solve() { 

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    vector<int> v(n);

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

        v[i] = (i % 3);

    }



    if(n % 3 != 0) {

        v[n - 1] = 1;

        v[n - 2] = 0;

    }



    int l = (x - 1 + n) % n;

    int r = (x + 1) % n;



    set<int> st = {v[l], v[r], v[y]};

    int mex = 0;

    while(st.count(mex)) mex++;



    if(v[x] != mex) {

        v[x] = mex;

    }



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

        if(i == x || i == y) continue;

        st.clear();

        l = (i - 1 + n) % n;

        r = (i + 1) % n;

        st.insert(v[l]);

        st.insert(v[r]);

        int mex = 0;

        while(st.count(mex)) mex++;

        if(v[i] != mex) v[i] = mex;

    }



    for(auto x : v) {

        cout << x << " ";

    }

    cout << "\n";

}          

int main() {

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

    int t = 1, cs = 1;  

    cin >> t;

    while (t--) {

        //cout << "Case " << cs++ << ": ";

        solve();

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;

int main()

{

int t;

cin>>t;

while (t--){

int n;

cin>>n;

vector<int> arr(n,0);

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

cin>>arr[i];

}

int cnt=0;

int sum=0;

int sign=1;

bool f=true;

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

if (arr[i] <= arr[i+1]){

sum += sign*arr[i];

sign *= -1;

}

else{

if (arr[i] - sum <= arr[i+1]){

sum=0;

sign=1;

continue;

}

else{

f=false;

break;

}

}

}

if (f){

cout<<"YES"<<endl;

}

else{

cout<<"NO"<<endl;

}

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):


#include <bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while (t--){

int n;

cin>>n;

vector<int> arr(n,0);

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

cin>>arr[i];

}

bool f=true;

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

int x=arr[i];

arr[i]-=x;

arr[i+1]-=x;

if (arr[i] < 0){

f=false;

break;

}

}

if (f){

cout<<"YES"<<endl;

}

else{

cout<<"NO"<<endl;

}

}



return 0;

}

Submission (verdict: Accepted):












#include <bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while (t--){

int n;

cin>>n;

vector<int> arr(n,0);

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

cin>>arr[i];

}

bool f=true;

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

int x=arr[i];

arr[i]-=x;

arr[i+1]-=x;

if (arr[i+1] < 0){

f=false;

break;

}

}

if (f){

cout<<"YES"<<endl;

}

else{

cout<<"NO"<<endl;

}

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

int main()

{

int t;

cin>>t;

while (t--){

int n;

cin>>n;

vector<int> arr(n,0);

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

cin>>arr[i];

}

int cnt=0;

int sum=0;

int sign=1;

bool f=true;

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

if (arr[i] <= arr[i+1]){

sum += sign*arr[i];

sign *= -1;

}

else{

if (arr[i] - sum <= arr[i+1]){

sum=0;

sign=1;

continue;

}

else{

f=false;

break;

}

}

}

if (f){

cout<<"YES"<<endl;

}

else{

cout<<"NO"<<endl;

}

}



return 0;

}

Submission (verdict: Wrong answer on test 1):


#include <bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while (t--){

int n;

cin>>n;

vector<int> arr(n,0);

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

cin>>arr[i];

}

bool f=true;

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

int x=arr[i];

arr[i]-=x;

arr[i+1]-=x;

if (arr[i] < 0){

f=false;

break;

}

}

if (f){

cout<<"YES"<<endl;

}

else{

cout<<"NO"<<endl;

}

}



return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

class Group {
    public:
    vector<int> memberIndexes;

    Group(){}
    
    void add(int x){memberIndexes.push_back(x);}
    int size(){return (memberIndexes.size());}
    
    bool operator < (Group rhs){
        return this->size() < rhs.size();
    }
};

int main(){
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}
        // put into groups that can be removed together
        // minimize groups
        // groups are contigous seperated by lower numbers
        // for each number store group (what information about the group. indexes? l and r of range. )
        // we need to store the amount of members of each group, and an arr of the locations (and thus the range)
        vector<int> numArr;
        unordered_map<int, int> numNums;
        for (int i : arr){
            if (numNums.count(i)) { 
                (numNums[i] += 1);
            } else {
                numNums[i] = 1;
                numArr.push_back(i);


            }
        }
        vector<int> amtNums;
        for (int i : numArr){amtNums.push_back(numNums[i]);}
        sort(amtNums.begin(), amtNums.end());
        int groupsRmed = 0;
        for (int i : amtNums){
            k -= i;
            if (k < 0){
                break;
            } else {
                groupsRmed++;


            }
        }
        int res = (size(numArr) - groupsRmed != 0) ? (size(numArr) - groupsRmed) : 1;
        cout << res << "\n";
        







    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}
        // put into groups that can be removed together
        // minimize groups
        // groups are contigous seperated by lower numbers
        // for each number store group (what information about the group. indexes? l and r of range. )
        // we need to store the amount of members of each group, and an arr of the locations (and thus the range)
        vector<int> numArr;
        unordered_map<int, int> numNums;
        for (int i : arr){
            if (numNums.count(i)) { 
                (numNums[i] += 1);
            } else {
                numNums[i] = 1;
                numArr.push_back(i);


            }
        }
        vector<int> amtNums;
        for (int i : numArr){amtNums.push_back(numNums[i]);}
        sort(amtNums.begin(), amtNums.end());
        int groupsRmed = 0;
        for (int i : amtNums){
            k -= i;
            if (k < 0){
                break;
            } else {
                groupsRmed++;


            }
        }
        int res = (size(numArr) - groupsRmed != 0) ? (size(numArr) - groupsRmed) : 1;
        cout << res << "\n";
        







    }
}


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

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}


        sort(arr.begin(), arr.end());
        // apearances, num
        vector<pair<int, int>> numUnique;
        int currApperances = 0;
        int last = arr[0];
        for (int i : arr){
            if (i == last){
                currApperances++;
            } else {
                numUnique.emplace_back(currApperances, last);
                currApperances = 1;
                last = i;
            }
        }
        numUnique.emplace_back(currApperances, last);

        sort(numUnique.begin(), numUnique.end());
        int removals = 0;
        for (pair<int, int> i : numUnique){
            k -= i.first;
            if (k < 0){
                break;
            }
            else{
                removals++;
            }
        }
        int res = (size(numUnique) - removals != 0) ? size(numUnique) - removals : 1;
        cout << res << "\n";

        

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

Previous submission (verdict: Wrong answer on test 2):
//#include <bits/stdc++.h>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			}
		}
		int maxnums=0;
		for(int i=1;i<=n;i++)
		{
			if(dev[i]==maxl)
			{
				maxnums++;
			}
		}
		if(maxnums>2)
		{
			cout<<maxnums*2<<endl;
			continue;
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	return 0;
}

















Submission (verdict: Wrong answer on test 2):
//#include <bits/stdc++.h>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			}
		}
		int maxnums=0;
		for(int i=1;i<=n;i++)
		{
			if(dev[i]==maxl)
			{
				maxnums++;
			}
		}
		if(maxnums>2)
		{
			cout<<maxnums*2-1<<endl;
			continue;
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	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>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			}
		}
		int maxnums=0;
		for(int i=1;i<=n;i++)
		{
			if(dev[i]==maxl)
			{
				maxnums++;
			}
		}
		if(maxnums>2)
		{
			cout<<maxnums*2-1<<endl;
			continue;
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	return 0;
}

















Submission (verdict: Accepted):
//#include <bits/stdc++.h>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		map<int, int> maxson;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < arr[i].size(); j++) {
				maxson[i] = max(dev[arr[i][j]], maxson[i]);
			}
		}
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			} else if (dev[i] == maxl) {
				if (maxson[i] < maxson[num])
					num = i;
			}
		}
		int maxnums = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] == maxl) {
				maxnums++;
			}
		}
		if (maxnums > 2) {
			cout << maxl*2 - 1 << endl;
			continue;
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl && i != num) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
//#include <bits/stdc++.h>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			}
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	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>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		map<int, int> maxson;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < arr[i].size(); j++) {
				maxson[i] = max(dev[arr[i][j]], maxson[i]);
			}
		}
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			} else if (dev[i] == maxl) {
				if (maxson[i] < maxson[num])
					num = i;
			}
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl && i != num) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	return 0;
}

















Submission (verdict: Wrong answer on test 2):
//#include <bits/stdc++.h>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			}
		}
		int maxnums=0;
		for(int i=1;i<=n;i++)
		{
			if(dev[i]==maxl)
			{
				maxnums++;
			}
		}
		if(maxnums>2)
		{
			cout<<maxnums*2<<endl;
			continue;
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	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>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			}
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	return 0;
}

















Submission (verdict: Wrong answer on test 2):
//#include <bits/stdc++.h>
//__builtin_popcountll(long long number); 二进制数数字1的个数
//__builtin_popcount(int number);二进制数数字1的个数
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f;
#define int long long
#define lowbit(x) ((x)&(-x))
#define endl '\n'
typedef pair<int, int> PII;
const int N = 200010;

vector<int> arr[N];

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	int num = 1;
	int T, n;
	int a, b;
	cin >> T;
	while (T--) {

		map<int, int> dev;
		map<int, int> maxson;
		cin >> n;
		for (int i = 1; i <= n; i++)
			arr[i].clear();
		for (int i = 1; i <= n - 1; i++) {

			cin >> a >> b;
			dev[a]++;
			dev[b]++;
			arr[a].push_back(b);
			arr[b].push_back(a);
		}
		int num = 0;
		int maxl = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < arr[i].size(); j++) {
				maxson[i] = max(dev[arr[i][j]], maxson[i]);
			}
		}
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl) {
				maxl = dev[i];
				num = i;
			} else if (dev[i] == maxl) {
				if (maxson[i] < maxson[num])
					num = i;
			}
		}
		int ans = 1;
		ans += maxl - 1;
		dev[num] = 0;
		for (int i = 0; i < arr[num].size(); i++) {
			dev[arr[num][i]]--;
		}
		maxl = 0;
		for (int i = 1; i <= n; i++) {
			if (dev[i] > maxl && i != num) {
				maxl = dev[i];
			}
		}
		ans += maxl - 1;
		cout << ans << endl;
	}
	return 0;
}