ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define pii pair<int, int> 
#define lowbit(x) (x&-x) 
#define ll long long  
#define ull unsigned long long
#define endl "\n"
const int mod = 998244353;
const int inf = 1e9;
const ll llf = 1e18;
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j;
	int n, m;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int x;
		map<int, int>mapa;
		map<int, int>mapb;
		bool flag = 1;
		cin >> n >> m;
		while (n--)
		{
			cin >> x;
			mapa[x]++;
		}
		while (m--)
		{
			cin >> x;
			mapb[x]++;
		}
		int cnt = 0;
		for (auto it = mapb.rbegin();it != mapb.rend();it++)
		{
			//if (cnt == 2)
			//	it--;
			if (it->first == 1)
			{
				if (mapa[1] == mapb[1])
				{
					mapa.erase(1);
					mapb.erase(1);
				}
				else
					flag = 0;
				break;
			}
			if (mapa[it->first] > it->second)
			{
				flag = 0;
				break;
			}

			cnt = 0;
			if (mapb.find(it->first / 2) == mapb.end())cnt++;
			if (mapb.find(it->first / 2) == mapb.end())cnt++;

			mapb[it->first/2] += it->second - mapa[it->first];
			mapb[it->first - it->first / 2] += it->second - mapa[it->first];
			
			mapb[it->first] = mapa[it->first] = 0;
		}
		int flag1 = 1, flag2 = 1;
		for (auto x : mapa)
			if (x.second)
				flag1 = 0;
		for (auto x : mapb)
			if (x.second)
				flag2 = 0;
		if (flag && flag1 && flag2)
			cout << "YeS" << endl;
		else
			cout << "nO" << endl;
	}
}

Submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
#define pii pair<int, int> 
#define lowbit(x) (x&-x) 
#define ll long long  
#define ull unsigned long long
#define endl "\n"
const int mod = 998244353;
const int inf = 1e9;
const ll llf = 1e18;
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j;
	int n, m;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int x;
		map<int, int>mapa;
		map<int, int>mapb;
		bool flag = 1;
		cin >> n >> m;
		while (n--)
		{
			cin >> x;
			mapa[x]++;
		}
		while (m--)
		{
			cin >> x;
			mapb[x]++;
		}
		for (auto it = mapb.rbegin();it != mapb.rend();)
		{
			if (it->first == 1)
			{
				if (mapa[1] == mapb[1])
				{
					mapa.erase(1);
					mapb.erase(1);
				}
				else
					flag = 0;
				break;
			}
			if (mapa[it->first] > it->second)
			{
				flag = 0;
				break;
			}

			mapb[it->first/2] += it->second - mapa[it->first];
			mapb[it->first - it->first / 2] += it->second - mapa[it->first];

			mapa.erase(it->first);
			mapb.erase(it->first);
		}
		int flag1 = 1, flag2 = 1;
		for (auto x : mapa)
			if (x.second)
				flag1 = 0;
		for (auto x : mapb)
			if (x.second)
				flag2 = 0;
		if (flag && flag1 && flag2)
			cout << "YeS" << endl;
		else
			cout << "nO" << endl;
	}
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#define pii pair<int, int> 
#define lowbit(x) (x&-x) 
#define ll long long  
#define ull unsigned long long
#define endl "\n"
const int mod = 998244353;
const int inf = 1e9;
const ll llf = 1e18;
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j;
	int n, m;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int x;
		map<int, int>mapa;
		map<int, int>mapb;
		bool flag = 1;
		cin >> n >> m;
		while (n--)
		{
			cin >> x;
			mapa[x]++;
		}
		while (m--)
		{
			cin >> x;
			mapb[x]++;
		}
		int cnt = 0;
		for (auto it = mapb.rbegin();it != mapb.rend();it++)
		{
			//if (cnt == 2)
			//	it--;
			if (it->first == 1)
			{
				if (mapa[1] == mapb[1])
				{
					mapa.erase(1);
					mapb.erase(1);
				}
				else
					flag = 0;
				break;
			}
			if (mapa[it->first] > it->second)
			{
				flag = 0;
				break;
			}

			cnt = 0;
			if (mapb.find(it->first / 2) == mapb.end())cnt++;
			if (mapb.find(it->first / 2) == mapb.end())cnt++;

			mapb[it->first/2] += it->second - mapa[it->first];
			mapb[it->first - it->first / 2] += it->second - mapa[it->first];
			
			mapb[it->first] = mapa[it->first] = 0;
		}
		int flag1 = 1, flag2 = 1;
		for (auto x : mapa)
			if (x.second)
				flag1 = 0;
		for (auto x : mapb)
			if (x.second)
				flag2 = 0;
		if (flag && flag1 && flag2)
			cout << "YeS" << endl;
		else
			cout << "nO" << endl;
	}
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
#define pii pair<int, int> 
#define lowbit(x) (x&-x) 
#define ll long long  
#define ull unsigned long long
#define endl "\n"
const int mod = 998244353;
const int inf = 1e9;
const ll llf = 1e18;
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j;
	int n, m;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int x;
		map<int, int>mapa;
		map<int, int>mapb;
		bool flag = 1;
		cin >> n >> m;
		while (n--)
		{
			cin >> x;
			mapa[x]++;
		}
		while (m--)
		{
			cin >> x;
			mapb[x]++;
		}
		for (auto it = mapb.rbegin();it != mapb.rend();)
		{
			if (it->first == 1)
			{
				if (mapa[1] == mapb[1])
				{
					mapa.erase(1);
					mapb.erase(1);
				}
				else
					flag = 0;
				break;
			}
			if (mapa[it->first] > it->second)
			{
				flag = 0;
				break;
			}

			mapb[it->first/2] += it->second - mapa[it->first];
			mapb[it->first - it->first / 2] += it->second - mapa[it->first];

			mapa.erase(it->first);
			mapb.erase(it->first);
		}
		int flag1 = 1, flag2 = 1;
		for (auto x : mapa)
			if (x.second)
				flag1 = 0;
		for (auto x : mapb)
			if (x.second)
				flag2 = 0;
		if (flag && flag1 && flag2)
			cout << "YeS" << endl;
		else
			cout << "nO" << endl;
	}
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define pii pair<int, int> 
#define lowbit(x) (x&-x) 
#define ll long long  
#define ull unsigned long long
#define endl "\n"
const int mod = 998244353;
const int inf = 1e9;
const ll llf = 1e18;
using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int i, j;
	int n, m;
	int tt;
	cin >> tt;
	while (tt--)
	{
		int x;
		map<int, int>mymap;
		bool flag = 1;
		cin >> n >> m;
		while (n--)
		{
			cin >> x;
			mymap[x]--;
		}
		while (m--)
		{
			cin >> x;
			mymap[x]++;
		}
		for (auto it =mymap.rbegin();it != mymap.rend();)
		{
			if (it->first== 1)
			{
				if (it->second)
					flag = 0;
			}
			if (it->second < 0)
			{
				flag = 0;
				break;
			}
			mymap[it->first / 2] += it->second;
			mymap[it->first - it->first / 2] += it->second;
			mymap.erase(it->first);
		}
		int flag1 = 1;
		for (auto x : mymap)
		{
			if (x.second)
				flag1 = 0;
		}
		if (flag && flag1)
			cout << "YeS" << endl;
		else
			cout << "nO" << endl;
	}
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



bool flag = false;



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

{

if(arr[i+1] >= arr[i])

{

flag = true;

}

else flag = false;

}



if(flag)

{

cout << "YES" << endl;

return;

}





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

{

if(min(arr[i],arr[i+1]) == arr[i])

{

arr[i] = 0;

arr[i+1] -= arr[i];

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



//bool flag = true;

// for(auto i : arr)

//     cout << i << " ";



// cout << endl;



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

{

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

{

return false;

}

//else flag = false;

}



return true;;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



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

{

if(check(arr))

{

cout << "YES" << endl;

return;

}



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

{

arr[i+1] = arr[i+1] - arr[i];

arr[i] = 0;

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}

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

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



//bool flag = true;

// for(auto i : arr)

//     cout << i << " ";



// cout << endl;



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

{

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

{

return false;

}

//else flag = false;

}



return true;;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



if(check(arr))

{

cout << "YES" << endl;

return;

}



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

{

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

{

arr[i+1] = arr[i+1] - arr[i];

arr[i] = 0;

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



bool flag = false;



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

{

if(arr[i+1] >= arr[i])

{

flag = true;

}

else flag = false;

}



return flag;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



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

{

if(check(arr))

{

cout << "YES" << endl;

return;

}



if(min(arr[i],arr[i+1]) == arr[i])

{

arr[i] = 0;

arr[i+1] -= arr[i];

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}

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

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



bool flag = false;



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

{

if(arr[i+1] >= arr[i])

{

flag = true;

}

else flag = false;

}



return flag;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



for(int i = 1 ; i < n ; i++)

{

if(check(arr))

{

cout << "YES" << endl;

return;

}



if(arr[i-1] <= arr[i])

{

arr[i-1] = 0;

arr[i] -= arr[i-1];

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



bool flag = false;



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

{

if(arr[i+1] >= arr[i])

{

flag = true;

}

else flag = false;

}



return flag;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



for(int i = 1 ; i < n ; i++)

{

if(check(arr))

{

cout << "YES" << endl;

return;

}



if(arr[i-1] <= arr[i])

{

arr[i-1] = 0;

arr[i] -= arr[i-1];

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}

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

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



//bool flag = true;

// for(auto i : arr)

//     cout << i << " ";



// cout << endl;



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

{

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

{

return false;

}

//else flag = false;

}



return true;;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



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

{

if(check(arr))

{

cout << "YES" << endl;

return;

}



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

{

arr[i+1] = arr[i+1] - arr[i];

arr[i] = 0;

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



bool flag = false;



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

{

if(arr[i+1] >= arr[i])

{

flag = true;

}

else flag = false;

}



if(flag)

{

cout << "YES" << endl;

return;

}





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

{

if(min(arr[i],arr[i+1]) == arr[i])

{

arr[i] = 0;

arr[i+1] -= arr[i];

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}

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

using namespace std;





bool check(vector<int>& arr)

{

int n = arr.size();



bool flag = false;



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

{

if(arr[i+1] >= arr[i])

{

flag = true;

}

else flag = false;

}



return flag;

}



void solve()

{

int n;

cin >> n;



vector<int> arr(n);



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

{

cin >> arr[i];

}



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

{

if(check(arr))

{

cout << "YES" << endl;

return;

}



if(min(arr[i],arr[i+1]) == arr[i])

{

arr[i] = 0;

arr[i+1] -= arr[i];

}



else

{

cout << "NO" << endl;

return;

}

}



cout << "YES" << endl;



}



int main()

{

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

cout.tie(nullptr);



int t;

cin >> t;

//t = 1;



while (t--)

{

solve();

}



return 0;

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

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

        mp[s[i]]++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

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

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

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

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"/n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)

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

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

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

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"/n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}

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

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

    ll p=0,q=0,r=0;

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

        mp[s[i]]++;

        if(s[i]=='s') p++;

        if(s[i]=='p') q++;

        if(s[i]=='.') r++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp.size()==2 && (p+r==n || q+r==n)){

        cout<<"YES"<<"\n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin>>t;

    while(t--){

        solve();

    }

}
Problem: 2049B - pspspsps
Language: C++17 (GCC 7-32)


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

#define all(s) s.begin(), s.end()

using namespace std;

using ll = long long;

using ull = unsigned long long;

const int _N = 1e5 + 5;



void solve(){

    ll n;

    cin>>n;

	string s;

	cin>>s;

    map<char,ll> mp;

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

        mp[s[i]]++;

    }



    if(mp.size()==1){

        cout<<"YES"<<"\n";

    }

    else if(mp['s']==1 && s[0]=='s'){

        cout<<"YES"<<"\n";

    }

    else if(mp['p']==1 && s[n-1]=='p'){

        cout<<"YES"<<"\n";

    }

    else{

        cout<<"NO"<<"\n";

    }

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    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>
#define all(s) s.begin(), s.end()
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int _N = 1e5 + 5;
ll n;

void check(ll v, vector<set<ll>> &adj){
    for(ll i=1; i<adj.size(); i++){
        if(adj[i].find(v)!=adj[i].end()){
            adj[i].erase(v);
        }
    }
}

void dfs(ll node, vector<set<ll>> &adj, vector<ll> &vis){
    vis[node]=1;
    for(auto i: adj[node]){
        if(vis[i]) continue;
        dfs(i,adj,vis);
    }
}

int main(){
	int t;
	cin>>t;
	while(t--){
		cin>>n;
        ll ans1,ans2;
        ll maxi=0;
		vector<set<ll>> adj(n+1);
        set<pair<ll,ll>> st;
        for(ll i=0; i<n-1; i++){
            ll u,v;
            cin>>u>>v;
            st.insert({u,v});
            adj[u].insert(v);
            adj[v].insert(u);
        }

        for(ll i=1; i<=n; i++){
            if(adj[i].size()>maxi){
                maxi=adj[i].size();
            }
        }

        vector<ll> v;
        for(ll i=1; i<=n; i++){
            if(adj[i].size()==maxi) v.push_back(i);
        }

        if(v.size()>2){
            ll x=v[0],y=v[1],z=v[2];
            if(st.find({x,y})!=st.end()){
                ans1=x;
                ans2=y;
            }
            if(st.find({y,z})!=st.end()){
                ans1=y;
                ans2=z;
            }
            if(st.find({x,z})!=st.end()){
                ans1=x;
                ans2=z;
            }
            check(ans1,adj);
            check(ans2,adj);
        }
        if(v.size()==2){
            ans1=v[0],ans2=v[1];
            check(ans1,adj);
            check(ans2,adj);
        }
        if(v.size()==1){
            ans1=v[0];
            check(ans1,adj);
            maxi=0;
            for(ll i=1; i<=n; i++){
                if(i==ans1) continue;
                if(adj[i].size()>maxi){
                    maxi=adj[i].size();
                }
            }
            for(ll i=1; i<=n; i++){
                if(adj[i].size()==maxi) ans2=i;
            }
            check(ans2,adj);
        }

        ll ans=0;
        vector<ll> vis(n+1,0);
        vis[ans1]=1;
        vis[ans2]=1;
        for(ll i=1; i<=n; i++){
            if(!vis[i]){
                dfs(i,adj,vis);
                ans++;
            }
        }

        cout<<ans<<endl;  
	}
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

#include <algorithm>

#include <cstring>

#include <vector>

#include <queue>

#include <deque>

#include <cmath>

#include <map>

#include <set>

#define endl '\n'

#define db(a) cout << #a << "=" << (a) << endl;

#define x first

#define y second

using namespace std;



const int N = 2e5 + 10, M = 2e5 + 10, INF = 0x3f3f3f3f;



typedef long long ll;



typedef pair<int, int> PII;



int T;

int a[N];



int main() {

	cin >> T;

	while(T --){

		int n, l, r;

		cin >> n >> l >> r;

		for(int i = 0; i < n; i ++) cin >> a[i];

		sort(a, a + n);

		int len = r - l + 1;

		ll ans = 0;

		for(int i = 0; i < len; i ++) ans += a[i];

		cout << ans << endl;

	}

    return 0;

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

Previous submission (verdict: Wrong answer on test 8):
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#define endl '\n'
#define db(a) cout << #a << "=" << (a) << endl;
#define x first
#define y second
using namespace std;

const int N = 2e5 + 10, M = 2e5 + 10, INF = 0x3f3f3f3f;

typedef long long ll;

typedef pair<int, int> PII;

int T;
ll a[N], b[N], c[N];

int main() {
	cin >> T;
	while(T --){
		int n, l, r;
		cin >> n >> l >> r;
		for(int i = 1; i <= n; i ++){
			cin >> a[i];
			b[i] = a[i];
			c[i] = a[i];
		} 
		sort(b + 1, b + r + 1);
		sort(c + l, c + n + 1);
		int len = r - l + 1;
		ll s1 = 0, s2 = 0;
		for(int i = 1; i <= len; i ++) s1 += b[i];
		for(int i = l; i < l + len; i ++) s2 += c[i];
		int ans = min(s1, s2);
		cout << ans << endl;
	}
    return 0;
}




Submission (verdict: Accepted):
#include <iostream>

#include <algorithm>

#include <cstring>

#include <vector>

#include <queue>

#include <deque>

#include <cmath>

#include <map>

#include <set>

#define endl '\n'

#define db(a) cout << #a << "=" << (a) << endl;

#define x first

#define y second

using namespace std;



const int N = 2e5 + 10, M = 2e5 + 10, INF = 0x3f3f3f3f;



typedef long long ll;



typedef pair<int, int> PII;



int T;

ll a[N], b[N], c[N];



int main() {

	cin >> T;

	while(T --){

		int n, l, r;

		cin >> n >> l >> r;

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

			cin >> a[i];

			b[i] = a[i];

			c[i] = a[i];

		} 

		sort(b + 1, b + r + 1);

		sort(c + l, c + n + 1);

		int len = r - l + 1;

		ll s1 = 0, s2 = 0;

		for(int i = 1; i <= len; i ++) s1 += b[i];

		for(int i = l; i < l + len; i ++) s2 += c[i];

		ll ans = min(s1, s2);

		cout << ans << endl;

	}

    return 0;

}