ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
ifstream fin("window.in");
ofstream fout("window.out");
void solve(){
    int l,r;
    cin>>l>>r;
    int b(30),prc(0);
    while(((1<<b)&l)==((1<<b)&r))b--,prc+=((1<<b)&r);
    if(prc+(1<<b)==r)cout<<(1<<b)<<" "<<(1<<b)-1<<" "<<(1<<b)-2<<"\n";
    else cout<<(1<<b)<<" "<<(1<<b)-1<<" "<<(1<<b)+1<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long t;
    cin>>t;
    while(t--)solve();
    return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
ifstream fin("window.in");
ofstream fout("window.out");
void solve(){
    int l,r;
    cin>>l>>r;
    int b(30),prc(0);
    while(((1<<b)&l)==((1<<b)&r))prc+=((1<<b)&r),b--;
    if(prc+(1<<b)==r)cout<<prc+(1<<b)<<" "<<prc+(1<<b)-1<<" "<<prc+(1<<b)-2<<"\n";
    else cout<<prc+(1<<b)<<" "<<prc+(1<<b)-1<<" "<<prc+(1<<b)+1<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long t;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
ifstream fin("window.in");
ofstream fout("window.out");
void solve(){
    int l,r;
    cin>>l>>r;
    int b(30);
    while(((1<<b)&l)==((1<<b)&r))b--;
    cout<<(1<<b)<<" "<<(1<<b)-1<<" "<<(1<<b)-1<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long t;
    cin>>t;
    while(t--)solve();
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
ifstream fin("window.in");
ofstream fout("window.out");
void solve(){
    int l,r;
    cin>>l>>r;
    int b(30);
    while(((1<<b)&l)==((1<<b)&r))b--;
    cout<<(1<<b)<<" "<<(1<<b)-1<<" "<<(1<<b)-2<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long t;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
ifstream fin("window.in");
ofstream fout("window.out");
void solve(){
    int l,r;
    cin>>l>>r;
    int b(30);
    while(((1<<b)&l)==((1<<b)&r))b--;
    cout<<(1<<b)<<" "<<(1<<b)-1<<" "<<(1<<b)-1<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long t;
    cin>>t;
    while(t--)solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

#define all(A) A.begin(),A.end()
#define fori(i, k, n) for (int i = k; i < n; i++)
#define ln "\n"


vector<unordered_set<int> > adj;
vector<pair<int, int> > deg;
vector<bool> visited;
int n, ans;

void dfs(int u) {
    visited[u] = true;
    for (const auto &v: adj[u])
        if (!visited[v]) {
            ans = max(ans, deg[u].first + deg[v].first - 2);
            dfs(v);
        }
}

bool vecinos(int u, int v) {
    return adj[u].find(v) != adj[u].end();
}


void solve() {
    cin >> n;
    adj.assign(n, unordered_set<int>());
    deg.assign(n, {0, 0});
    visited.assign(n, false);
    fori(i, 0, n)
        deg[i].second = i;
    fori(i, 0, n-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].insert(b);
        adj[b].insert(a);
        deg[a].first++;
        deg[b].first++;
    }
    ans = 0;
    dfs(0);
    sort(all(deg), greater<pair<int, int> >());
    fori(i, 0, n) {
        fori(j, i+1, n) {
            if (vecinos(deg[i].second, deg[j].second))
                continue;
            ans = max(ans, deg[i].first + deg[j].first - 1);
            cout << ans << ln;
            return;
        }
    }
    cout << ans << ln;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}


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

#define all(A) A.begin(),A.end()
#define fori(i, k, n) for (int i = k; i < n; i++)
#define ln "\n"


vector<unordered_set<int> > adj;
vector<pair<int, int> > deg;
vector<bool> visited;
int n, ans;

void dfs(int u) {
    visited[u] = true;
    for (const auto &v: adj[u])
        if (!visited[v]) {
            ans = max(ans, deg[u].first + deg[v].first - 2);
            dfs(v);
        }
}

bool vecinos(int u, int v) {
    return adj[u].find(v) != adj[u].end();
}


void solve() {
    cin >> n;
    adj.assign(n, unordered_set<int>());
    deg.assign(n, {0, 0});
    visited.assign(n, false);
    fori(i, 0, n)
        deg[i].second = i;
    fori(i, 0, n-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].insert(b);
        adj[b].insert(a);
        deg[a].first++;
        deg[b].first++;
    }
    ans = 0;
    dfs(0);
    sort(all(deg), greater<pair<int, int> >());
    fori(i, 0, n) {
        fori(j, i+1, n) {
            if (vecinos(deg[i].second, deg[j].second))
                continue;
            ans = max(ans, deg[i].first + deg[j].first - 1);
            break;
        }
    }
    cout << ans << ln;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 2):
using namespace std;
#include <bits/stdc++.h>

#define all(A) A.begin(),A.end()
#define fori(i, k, n) for (int i = k; i < n; i++)
#define ln "\n"


vector<vector<int> > adj;
vector<int> deg;
vector<bool> visited;
int n, U, V;

void removeVertex(int u) {
    deg[u] = 0;
    for (const auto &v: adj[u]) {
        adj[v].erase(remove(all(adj[v]), u), adj[v].end());
        deg[v]--;
    }
    adj.erase(adj.begin() + u);
}

void dfs(int u) {
    visited[u] = true;
    for (const auto &v: adj[u])
        if (!visited[v])
            dfs(v);
}

void printGraph() {
    fori(u, 0, n) {
        cout << (u + 1) << "->";
        for (const auto &v: adj[u])
            cout << (v + 1) << ", ";
        cout << ln;
    }
}


void solve() {
    cin >> n;
    adj.assign(n, vector<int>());
    deg.assign(n, 0);

    fori(i, 0, n-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }
    set<pair<int, int> > tree;
    fori(u, 0, n)
        tree.insert({deg[u], u});
    auto first = prev(tree.end());
    tree.erase(first);
    U = first->second;
    removeVertex(U);
    tree.clear();
    fori(u, 0, n) {
        if (u == U)
            continue;
        tree.insert({deg[u], u});
    }
    V = prev(tree.end())->second;
    removeVertex(V);
    visited.assign(n, false);
 //   cout << "U: " << U + 1 << " V: " << V + 1 << ln;
    int ans = 0;
    fori(u, 0, n) {
        if (u != U && u != V && !visited[u]) {
            //cout << "u: " << u + 1 << ln;
            dfs(u);
            ans++;
        }
    }
    cout << ans << ln;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

string a = "";

int mx, itr;

while(s.size()) {

mx = -1;

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

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

mx = (s[i]-'0') - i;

itr = i;

if (mx>9-i-1) break;

}

}

a = a + to_string(mx);

s.erase(s.begin()+ itr);

}

cout<<a<<'\n';

}

return 0;

}



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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

int a;

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

for (int j = i; j >0 ; j--) {

if (s[j]-1>s[j-1]) {

a = s[j]-1;

s[j] = s[j-1];

s[j-1] = a;

}else break;

}

}

cout<<s<<'\n';

}

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

string a = "";

int mx, itr;

while(s.size()) {

mx = -1;

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

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

mx = (s[i]-'0') - i;

itr = i;

}

}

a = a + to_string(mx);

s.erase(s.begin()+ itr);

}

cout<<a<<'\n';

}

return 0;

}



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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

string a = "";

int mx, itr;

while(s.size()) {

mx = -1;

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

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

mx = (s[i]-'0') - i;

itr = i;

if (mx>9-i-1) break;

}

}

a = a + to_string(mx);

s.erase(s.begin()+ itr);

}

cout<<a<<'\n';

}

return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

using namespace std;



int32_t main() {

ios::sync_with_stdio(false);

cin.tie(nullptr);

int tc;

cin>>tc;

string s;

while(tc--){

cin>>s;

string a = "";

int mx, itr;

while(s.size()) {

mx = -1;

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

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

mx = (s[i]-'0') - i;

itr = i;

}

}

a = a + to_string(mx);

s.erase(s.begin()+ itr);

}

cout<<a<<'\n';

}

return 0;

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

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define lowbit(x) ((x) & (-x))
#define ar2 array<ll, 2>
#define ar3 array<ll, 3>
#define ULL unsigned long long
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int mod1 = 1331;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
ll n, m, q, k, a[N];
void solve()
{
  string s;
  cin >> s;
  n = s.size();
  s = " " + s;
  for (int i = 1; i <= n; i++)
  {
    string t = s.substr(i, i + min(10LL, n - i));
    ll pos = -1;
    ll mx = -llinf;
    for (int j = 0; j < t.size(); j++)
    {
      if ((t[j] - '0' - j) > mx)
      {
        pos = j;
        mx = (t[j] - '0' - j);
      }
    }
    string tmp = "";
    if (pos != -1)
    {
      tmp += mx + '0';
    }
    for (int j = 0; j < t.size(); j++)
    {
      if (j == pos)
      {
        continue;
      }
      tmp += t[j];
    }
    for (int j = 0; j < tmp.size(); j++)
    {
      s[i + j] = tmp[j];
    }
  }
  string ans = s.substr(1);
  cout << ans << endl;
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--)
    solve();
}
/*

*/

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define lowbit(x) ((x) & (-x))
#define ar2 array<ll, 2>
#define ar3 array<ll, 3>
#define ULL unsigned long long
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int mod1 = 1331;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
ll n, m, q, k, a[N];
void solve()
{
  string s;
  cin >> s;
  n = s.size();
  s = " " + s;
  for (int i = 1; i <= n; i++)
  {
    string t = s.substr(i, i + min(10LL, n - i));
    ll pos = -1;
    ll mx = -llinf;
    for (int j = 0; j < t.size(); j++)
    {
      if ((t[j] - '0' - j) > mx)
      {
        pos = j;
        mx = (t[j] - '0' - j);
      }
    }
    string tmp = "";
    if (pos != -1)
    {
      tmp += mx + '0';
    }
    for (int j = 0; j < t.size(); j++)
    {
      if (j == pos)
      {
        continue;
      }
      tmp += t[j];
    }
    for (int j = 0; j < tmp.size(); j++)
    {
      s[i + j] = tmp[j];
    }
  }
  for (int i = 1; i < s.size();i++)
  {
    cout << s[i];
  }
  cout << endl;
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--)
    solve();
}
/*

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


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define lowbit(x) ((x) & (-x))
#define ar2 array<ll, 2>
#define ar3 array<ll, 3>
#define ULL unsigned long long
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int mod1 = 1331;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
ll n, m, q, k, a[N];
void solve()
{
  string s;
  cin >> s;
  n = s.size();
  s = " " + s;
  for (int i = 1; i <= n; i++)
  {
    string t = s.substr(i, i + min(10LL, n - i));
    ll pos = -1;
    ll mx = -llinf;
    for (int j = 0; j < t.size(); j++)
    {
      if ((t[j] - '0' - j) > mx)
      {
        pos = j;
        mx = (t[j] - '0' - j);
      }
    }
    string tmp = "";
    if (pos != -1)
    {
      tmp += mx + '0';
    }
    for (int j = 0; j < t.size(); j++)
    {
      if (j == pos)
      {
        continue;
      }
      tmp += t[j];
    }
    for (int j = 0; j < tmp.size(); j++)
    {
      s[i + j] = tmp[j];
    }
  }
  string ans = s.substr(1);
  cout << ans << endl;
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--)
    solve();
}
/*

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

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define lowbit(x) ((x) & (-x))
#define ar2 array<ll, 2>
#define ar3 array<ll, 3>
#define ULL unsigned long long
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int mod1 = 1331;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
ll n, m, q, k, a[N];
void solve()
{
  string s;
  cin >> s;
  n = s.size();
  s = " " + s;
  for (int i = 1; i <= n; i++)
  {
    string t = s.substr(i, i + min(10LL, n - i));
    ll pos = -1;
    ll mx = -llinf;
    for (int j = 0; j < t.size(); j++)
    {
      if ((t[j] - '0' - j) > mx)
      {
        pos = j;
        mx = (t[j] - '0' - j);
      }
    }
    string tmp = "";
    if (pos != -1)
    {
      tmp += mx + '0';
    }
    for (int j = 0; j < t.size(); j++)
    {
      if (j == pos)
      {
        continue;
      }
      tmp += t[j];
    }
    for (int j = 0; j < tmp.size(); j++)
    {
      s[i + j] = tmp[j];
    }
  }
  for (int i = 1; i < s.size();i++)
  {
    cout << s[i];
  }
  cout << endl;
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--)
    solve();
}
/*

*/

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define lowbit(x) ((x) & (-x))
#define ar2 array<ll, 2>
#define ar3 array<ll, 3>
#define ULL unsigned long long
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int mod1 = 1331;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
ll n, m, q, k, a[N];
void solve()
{
  string s;
  cin >> s;
  n = s.size();
  s = " " + s;
  for (int i = 1; i <= n; i++)
  {
    string t = s.substr(i, min(10LL, n - i+1));
    ll pos = -1;
    ll mx = -llinf;
    for (int j = 0; j < t.size(); j++)
    {
      if ((t[j] - '0' - j) > mx)
      {
        pos = j;
        mx = (t[j] - '0' - j);
      }
    }
    string tmp = "";
    if (pos != -1)
    {
      tmp += mx + '0';
    }
    for (int j = 0; j < t.size(); j++)
    {
      if (j == pos)
      {
        continue;
      }
      tmp += t[j];
    }
    for (int j = 0; j < tmp.size(); j++)
    {
      s[i + j] = tmp[j];
    }
  }
  for (int i = 1; i < s.size();i++)
  {
    cout << s[i];
  }
  cout << endl;
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--)
    solve();
}
/*

*/
Problem: 2049C - MEX Cycle
Language: C++17 (GCC 7-32)


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

#include <bitset>

#include <cassert>

#include <cmath>

#include <iomanip>

#include <iostream>

#include <limits.h>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <string>

#include <vector>



#define  DBG(x         ) cerr<<#x<<" = "<<(x)<<endl;

#define DBG2(x, y      ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<endl;

#define DBG3(x, y, z   ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<endl;

#define DBG4(x, y, z, w) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<", "<<#w<<" = "<<(w)<<endl;

#define SEPA cerr<<" ============ "<<endl;



#define forn(i, n) for(int i = 0; i < int(n); i++)

#define fort(i, a, b) for(int i = int(a); i <= int(b); i++)



#define sz(s) int(s.size())

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

#define rall(s) s.rbegin(), s.rend()

#define pb push_back

#define endl '\n'

#define fst first

#define snd second

#define pii pair<int, int>

#define pll pair<long long, long long>

#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;



using namespace std;



void run_case(){

    int n, x, y; cin>>n>>x>>y;

    x--, y--;

    vector<int> ans(n);

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

        ans[i] = (i % 2 == 1);

    

    if(n & 1) ans[0] = 2;

    

    auto mex = [&](int a, int b, int c = 1e5){

        int res = 0;

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

            if(i != a && i != b && i != c){

                res = i; 

                break;

            }

        return res;

    };

    ans[x] = mex(ans[((x - 1) + n) % n], ans[(x + 1) % n]);

    ans[y] = mex(ans[((y - 1) + n) % n], ans[(y + 1) % n], ans[x]);

    for(int x : ans) cout<<x<<' '; cout<<endl;

}



int main(){

    fast_io

    //freopen("input.in", "r", stdin);

    bool mtc = true;

    int tc = 1; if(mtc) cin>>tc;

    for(int i = 0; i < tc; i++) run_case();

    return 0;

}
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;
template <typename T>
void read(T& x)
{
	x = 0;
	int f = 0, v = getchar();
	while(v != '-' && (v < '0' || v > '9')) v = getchar();
	if(v == '-') f = 1, v = getchar();
	while(v >= '0' && v <= '9') x = (x << 3) + (x << 1) + (v & 15), v = getchar();
	if(f) x = -x;
}
template <typename T>
void write(T x)
{
	if(x < 0) putchar('-'), x = -x;
	if(x < 10) putchar(x | 48);
	else write(x / 10), putchar(x % 10 | 48);
}
const int maxn = 1e5;
int t, n, u, v;
int sz[maxn + 5];
vector<int> g[maxn + 5];
int main(void)
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		int maxv = 0, maxi, ans = 1;
		for(int i = 1; i <= n; ++ i) 
		{
			g[i].clear();
			sz[i] = 0;
		}
		for(int i = 1; i < n; ++ i)
		{
			cin >> u >> v;
			++ sz[u], ++ sz[v];
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for(int i = 1; i <= n; ++ i)
		{
			if(sz[i] > maxv)
			{
				maxv = sz[i];
				maxi = i;
			}
		}
		ans += maxv - 1;
		maxv = 0;
		for(int i : g[maxi])
		{
			-- sz[i];
		} 
		for(int i = 1; i <= n; ++ i)
		{
			if(i == maxi) continue;
			maxv = max(maxv, sz[i]);
		}
		ans += maxv - 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>
using namespace std;
typedef long long ll;
template <typename T>
void read(T& x)
{
	x = 0;
	int f = 0, v = getchar();
	while(v != '-' && (v < '0' || v > '9')) v = getchar();
	if(v == '-') f = 1, v = getchar();
	while(v >= '0' && v <= '9') x = (x << 3) + (x << 1) + (v & 15), v = getchar();
	if(f) x = -x;
}
template <typename T>
void write(T x)
{
	if(x < 0) putchar('-'), x = -x;
	if(x < 10) putchar(x | 48);
	else write(x / 10), putchar(x % 10 | 48);
}
const int maxn = 1e5;
int t, n, u, v;
int sz[maxn + 5];
vector<int> g[maxn + 5];
int main(void)
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		int maxv = 0, maxi, ans = 1;
		for(int i = 1; i <= n; ++ i) 
		{
			g[i].clear();
			sz[i] = 0;
		}
		for(int i = 1; i < n; ++ i)
		{
			cin >> u >> v;
			++ sz[u], ++ sz[v];
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for(int i = 1; i <= n; ++ i)
		{
			if(sz[i] > maxv)
			{
				maxv = sz[i];
				maxi = i;
			}
		}
		ans += maxv - 1;
		maxv = 0;
		for(int i : g[maxi])
		{
			-- sz[i];
		} 
		for(int i = 1; i <= n; ++ i)
		{
			if(i == maxi) continue;
			maxv = max(maxv, sz[i]);
		}
		ans += maxv - 1;
		cout << ans<< endl;
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T>
void read(T& x)
{
	x = 0;
	int f = 0, v = getchar();
	while(v != '-' && (v < '0' || v > '9')) v = getchar();
	if(v == '-') f = 1, v = getchar();
	while(v >= '0' && v <= '9') x = (x << 3) + (x << 1) + (v & 15), v = getchar();
	if(f) x = -x;
}
template <typename T>
void write(T x)
{
	if(x < 0) putchar('-'), x = -x;
	if(x < 10) putchar(x | 48);
	else write(x / 10), putchar(x % 10 | 48);
}
const int maxn = 2e5;
int t, n, u, v;
int sz[maxn + 5];
vector<int> g[maxn + 5];
int main(void)
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		int maxv = 0, maxi, ans = 1;
		for(int i = 1; i <= n; ++ i) 
		{
			g[i].clear();
			sz[i] = 0;
		}
		for(int i = 1; i < n; ++ i)
		{
			cin >> u >> v;
			++ sz[u], ++ sz[v];
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for(int i = 1; i <= n; ++ i)
		{
			if(sz[i] > maxv)
			{
				maxv = sz[i];
				maxi = i;
			}
		}
		ans += maxv - 1;
		maxv = 0;
		for(int i : g[maxi])
		{
			-- sz[i];
		} 
		for(int i = 1; i <= n; ++ i)
		{
			if(i == maxi) continue;
			maxv = max(maxv, sz[i]);
		}
		ans += maxv - 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 <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

vector<bool> used;
vector<vector<int>> g;

void dfs(int u)
{
	used[u] = true;
	for (int v: g[u])
		if (!used[v])
			dfs(v);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(12);

	int t;
	cin >> t;

	while (t--) {
		int n;
		cin >> n;

		used.assign(n + 1, false);
		g.assign(n + 1, vector<int>());
		for (int i = 0; i < n - 1; ++i) {
			int u, v;
			cin >> u >> v;

			g[u].push_back(v);
			g[v].push_back(u);
		}

		int imax = 0;
		for (int i = 1; i < n + 1; ++i) {
			if (g[i].size() > g[imax].size())
				imax = i;
		}
		used[imax] = true;
		imax = 0;
		for (int i = 1; i < n + 1; ++i) {
			if (!used[i] && g[i].size() > g[imax].size())
				imax = i;
		}
		used[imax] = true;
		int ans = 0;
		for (int i = 1; i < n + 1; ++i) {
			if (used[i])
				continue;
			ans++;
			dfs(i);
		}

		cout << ans << "\n";
	}
}