ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void solve() {
    ll num;
    cin>>num;
    string n = to_string(num);
    int twos = 0, threes = 0;
    for(auto i: n){
        if(i=='2') twos++;
        else if (i=='3') threes++;
    }
    ll sum = 0;
    while(num>=10){
        ll digit = num%10;
        num = num/10;
        sum += digit;
    }
    sum += num;

    for (int i = 0; i <= min(twos, 8); ++i){
        for (int j = 0; j <= min(threes, 8); ++j){
            if((sum + 2*i + 6*j)%9==0){
                cout<<"yes"<<nl;
                return;
            }
        }
    }
    cout<<"no"<<nl;
}

int main() {
#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif
    fastio();
    auto start1 = high_resolution_clock::now();
    int TC = 1;
    cin >> TC;
    while(TC--)
        solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
#ifdef LOCAL
    cerr << "Time: " << duration . count() / 1000 << endl;
#endif
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void solve() {
    ll num;
    cin>>num;
    string n = to_string(num);
    int twos = 0, threes = 0;
    for(auto i: n){
        if(i=='2') twos++;
        else if (i=='3') threes++;
    }
    ll sum = 0;
    while(num>=10){
        ll digit = num%10;
        num = num/10;
        sum += digit;
    }
    sum += num;

    for (int i = 0; i <= min(twos, 8); ++i){
        for (int j = 0; j <= min(threes, 8); ++j){
            if((sum*1LL + 2*i + 6*j)%9==0){
                cout<<"yes"<<nl;
                return;
            }
        }
    }
    cout<<"no"<<nl;
}

int main() {
#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif
    fastio();
    auto start1 = high_resolution_clock::now();
    int TC = 1;
    cin >> TC;
    while(TC--)
        solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
#ifdef LOCAL
    cerr << "Time: " << duration . count() / 1000 << endl;
#endif
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void solve() {
    ll num;
    cin>>num;
    string n = to_string(num);
    int twos = 0, threes = 0;
    for(auto i: n){
        if(i=='2') twos++;
        else if (i=='3') threes++;
    }
    ll sum = 0;
    while(num>=10){
        ll digit = num%10;
        num = num/10;
        sum += digit;
    }
    sum += num;

    for (int i = 0; i <= min(twos, 8); ++i){
        for (int j = 0; j <= min(threes, 8); ++j){
            if((sum + 2*i + 6*j)%9==0){
                cout<<"yes"<<nl;
                return;
            }
        }
    }
    cout<<"no"<<nl;
}

int main() {
#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif
    fastio();
    auto start1 = high_resolution_clock::now();
    int TC = 1;
    cin >> TC;
    while(TC--)
        solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
#ifdef LOCAL
    cerr << "Time: " << duration . count() / 1000 << endl;
#endif
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

vector<ll> edges[200005]; 
ll degree[200005];

bool cmp(pair<ll,ll>& a,pair<ll,ll>& b){
    if(a.first==b.first) return a.second > b.second;
    return a.first > b.first;
}

void solve(ll tc = 0) {
    ll n; cin >> n;
    memset(degree,0,sizeof degree);
    for(ll i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        --u; --v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++){
        v.push_back({degree[i],i});
    }
    sort(v.begin(),v.end(),cmp);
    if(v.size()>2 && v[0].f == v[1].f && v[1].f == v[2].f){
        cout << 2*v[0].s-1 << endl;
        return;
    }
    ll x = v[0].s;
    ll y = v[0].f;
    for(ll i : edges[x]) degree[i]--;
    vector<pair<ll,ll>> ans;
    for(ll i=0;i<n;i++){
        if(i!=x) ans.push_back({degree[i],i});
    }
    sort(ans.begin(),ans.end(),cmp);
    ll z = ans[0].s;
    ll k = ans[0].f;
    ll res = y + k - 1;
    cout << res << endl;
}

int main() {
	send help
    
    cout << setprecision(12) << fixed;
	
	ll tc = 1;
	cin >> tc;
	for (ll t = 0; t < tc; t++) solve(t);
} 

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

bool cmp(pair<ll,ll>& a,pair<ll,ll>& b){
    if(a.first==b.first) return a.second > b.second;
    return a.first > b.first;
}

void solve(ll tc = 0) {
    ll n; cin >> n;
    // memset(degree,0,sizeof degree);
    vector<ll> edges[n];
    ll degree[n] = {0};
    for(ll i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        --u; --v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++){
        v.push_back({degree[i],i});
    }
    sort(v.begin(),v.end(),cmp);
    if(v.size()>2 && v[0].f == v[1].f && v[1].f == v[2].f){
        cout << 2*v[0].first-1 << endl;
        return;
    }
    ll x = v[0].s;
    ll y = v[0].f;
    for(ll i : edges[x]) degree[i]--;
    vector<pair<ll,ll>> ans;
    for(ll i=0;i<n;i++){
        if(i!=x) ans.push_back({degree[i],i});
    }
    sort(ans.begin(),ans.end(),cmp);
    ll z = ans[0].s;
    ll k = ans[0].f;
    ll res = y + k - 1;
    cout << res << endl;
}

int main() {
	send help
    
    cout << setprecision(12) << fixed;
	
	ll tc = 1;
	cin >> tc;
	for (ll t = 0; t < tc; t++) solve(t);
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

vector<ll> edges[200005]; 
ll degree[200005];

bool cmp(pair<ll,ll>& a,pair<ll,ll>& b){
    if(a.first==b.first) return a.second > b.second;
    return a.first > b.first;
}

void solve(ll tc = 0) {
    ll n; cin >> n;
    memset(degree,0,sizeof degree);
    for(ll i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        --u; --v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++){
        v.push_back({degree[i],i});
    }
    sort(v.begin(),v.end(),cmp);
    ll x = v[0].s;
    ll y = v[0].f;
    for(ll i : edges[x]) degree[i]--;
    vector<pair<ll,ll>> ans;
    for(ll i=0;i<n;i++){
        if(i!=x) ans.push_back({degree[i],i});
    }
    sort(ans.begin(),ans.end(),cmp);
    ll z = ans[0].s;
    ll k = ans[0].f;
    if(k==0) k++;
    ll res = y + k - 1;
    for(auto i : edges[x]){
        if(i==z) res--;
    }
    cout << res << endl;
}

int main() {
	send help
    
    cout << setprecision(12) << fixed;
	
	ll tc = 1;
	cin >> tc;
	for (ll t = 0; t < tc; t++) solve(t);
} 

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

vector<ll> edges[200005]; 
ll degree[200005];

bool cmp(pair<ll,ll>& a,pair<ll,ll>& b){
    if(a.first==b.first) return a.second > b.second;
    return a.first > b.first;
}

void solve(ll tc = 0) {
    ll n; cin >> n;
    memset(degree,0,sizeof degree);
    for(ll i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        --u; --v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++){
        v.push_back({degree[i],i});
    }
    sort(v.begin(),v.end(),cmp);
    if(v.size()>2 && v[0].f == v[1].f && v[1].f == v[2].f){
        cout << 2*v[0].s-1 << endl;
        return;
    }
    ll x = v[0].s;
    ll y = v[0].f;
    for(ll i : edges[x]) degree[i]--;
    vector<pair<ll,ll>> ans;
    for(ll i=0;i<n;i++){
        if(i!=x) ans.push_back({degree[i],i});
    }
    sort(ans.begin(),ans.end(),cmp);
    ll z = ans[0].s;
    ll k = ans[0].f;
    ll res = y + k - 1;
    cout << res << endl;
}

int main() {
	send help
    
    cout << setprecision(12) << fixed;
	
	ll tc = 1;
	cin >> tc;
	for (ll t = 0; t < tc; t++) solve(t);
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

vector<ll> edges[200005]; 
ll degree[200005];

bool cmp(pair<ll,ll>& a,pair<ll,ll>& b){
    if(a.first==b.first) return a.second > b.second;
    return a.first > b.first;
}

void solve(ll tc = 0) {
    ll n; cin >> n;
    memset(degree,0,sizeof degree);
    for(ll i=1;i<n;i++){
        ll u,v;
        cin >> u >> v;
        --u; --v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }
    vector<pair<ll,ll>> v;
    for(ll i=0;i<n;i++){
        v.push_back({degree[i],i});
    }
    sort(v.begin(),v.end(),cmp);
    ll x = v[0].s;
    ll y = v[0].f;
    for(ll i : edges[x]) degree[i]--;
    vector<pair<ll,ll>> ans;
    for(ll i=0;i<n;i++){
        if(i!=x) ans.push_back({degree[i],i});
    }
    sort(ans.begin(),ans.end(),cmp);
    ll z = ans[0].s;
    ll k = ans[0].f;
    if(k==0) k++;
    ll res = y + k - 1;
    for(auto i : edges[x]){
        if(i==z) res--;
    }
    cout << res << endl;
}

int main() {
	send help
    
    cout << setprecision(12) << fixed;
	
	ll tc = 1;
	cin >> tc;
	for (ll t = 0; t < tc; t++) solve(t);
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left esquerda
#define lb lower_bound
#define right direita
using namespace std;
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str( ),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9 + 7, MAXN = 2e5 + 5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

void solve() {
    ll l, r;
    cin >> l >> r;

    ll last = 1;
    while(last * 2 <= r) 
        last *= 2;

    if(last - 1 >= l && last + 1 <= r) {
        cout << last - 1 << " " << last << " " << last + 1 << endl;
        return;
    }

    if(last == r) {
        cout << l << " " << last - 1 << " " << last << endl;
        return;
    }

    if(last == l) {
        cout << r << " " << r << " " << l << endl;
    }


    ll aux = last;
    for(int i = 30; i >= 0 ; i--) 
        if(aux + (1ll << i) <= r && !(r & (1<<i)) ) {
            aux += (1ll <<i);
        }
    
    if(aux <= l)
        aux = l;

    cout << r << " " << r << " " << aux << endl;
}

int32_t main() {
    int ct;
    cin >> ct;
    while(ct--)
        solve();
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] >= a[i + 1])
        {
            cout << "NO\n";
            return;
        }
        int c = min(a[i], a[i + 1]);
        a[i] -= c;
        a[i + 1] -= c;
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    ll n;
    cin >> n;
    vector<int> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n-1; i++)
    {
        if (a[i] >= a[i + 1])
        {
            cout << "NO\n";
            return;
        }
        ll c = min(a[i], a[i + 1]);
        a[i] -= c;
        a[i + 1] -= c;
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    ll n;
    cin >> n;
    vector<int> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 1; i < n; i++)
    {
        if (a[i] < a[i-1])
        {
            cout << "NO\n";
            return;
        }
        ll c = min(a[i], a[i -1]);
        a[i] -= c;
        a[i-1] -= c;
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] >= a[i + 1])
        {
            cout << "NO\n";
            return;
        }
        int c = min(a[i], a[i + 1]);
        a[i] -= c;
        a[i + 1] -= c;
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    ll n;
    cin >> n;
    vector<int> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n-1; i++)
    {
        if (a[i] >= a[i + 1])
        {
            cout << "NO\n";
            return;
        }
        ll c = min(a[i], a[i + 1]);
        a[i] -= c;
        a[i + 1] -= c;
    }
    cout << "YES\n";
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 21):
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define lld long double
#define pll pair <ll, ll> 
#define f(i, a, b) for(ll i = a; i < b; i++)
#define br cout<<"\n";
const long long int N =  2e5+20;
const long long int M =  998244353;

ll binpow(ll x, ll y, ll MOD){
    ll res = 1; x %= MOD;
    while(y > 0){
        if(y&1ll){res = (res * x) % MOD;}
        x = (x * x) % MOD;
        y >>= 1LL;
    }
    res %= MOD;
    return res;
}


void solve(){ 
    ll n, m; 
    cin>>n>>m;
    vector <ll> a(n), b(m); 
    multiset <ll> s, t;
    f(i, 0, n){
        cin>>a[i];
        s.insert(a[i]);
    }
    f(j, 0, m){
        cin>>b[j];
        t.insert(b[j]);
    }
    ll mx; 
    while(t.size() < s.size()){
        vector <ll> v;
        for(auto x: t){
            if(s.find(x) != s.end()){
                s.erase(s.find(x));
            }
            else{
                v.push_back(x/2);
                v.push_back((x+1)/2);
            }
        }
        t.clear();
        assert(t.size() == 0);
        for(auto x: v){
            t.insert(x);
        }
        if(t.empty() || s.empty()){break;}
    }
    if(t.size() != s.size()){
        cout<<"NO\n";
        return;
    }
    for(auto x: t){
        if(s.find(x) == s.end()){
            cout<<"NO\n"; 
            return;
        }
        if(s.count(x) != t.count(x)){
            cout<<"NO\n";
            return;
        }
    }
    for(auto x: s){
        if(t.find(x) == t.end()){
            cout<<"NO\n"; 
            return;
        }
        if(s.count(x) != t.count(x)){
            cout<<"NO\n";
            return;
        }
    }
    cout<<"YES\n";
    return;
}   

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int TT = 1;
    cin >> TT;
    f(tt, 1, TT+1){
        solve();
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

signed main(){
    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        map<int,map<int,int>> map1;
        int maxi=0;int maxinode=0;
        map<int,int> map2;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            map1[u][v]=1;
            map1[v][u]=1;
            map2[u]++;map2[v]++;
            if(maxi<map2[u]){
                maxi=map2[u];
                maxinode=u;
            }
            if(maxi<map2[v]){
                maxi=map2[v];
                maxinode=v;
            }
        }
        int ans=maxi;
        for(auto x : map1[maxinode]){
            int v=x.first;
            map1[v].erase(maxinode);
            map2[v]--;
        }
        map1[maxinode].clear();
        map2.erase(maxinode);
        int maxi2=0;
        for(auto x : map2){
            maxi2=max(maxi2,x.second);
        }
        ans+=(maxi2-1);
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
using namespace std;
#define int long long int

signed main(){
    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        map<int,map<int,int>> map1;
        map<int,int> map2;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            map1[u][v]=1;
            map1[v][u]=1;
            map2[u]++;map2[v]++;
            
        }
        int res=0;
        for(int i=1;i<=n;i++){
            // delete this one
            int u=i;
            map<int,int> temp=map1[u];
            int ans=map2[u];
            map1[u].clear();
            map2.erase(u);
            for(auto x : temp){
                map1[x.first].erase(u);
                map2[x.first]--;
            }
            int maxi2=0;
            for(auto x : map2){
                maxi2=max(maxi2,x.second);
            }
            res=max(res,ans+(maxi2-1));
            map1[u]=temp;
            map2[u]=ans;
            for(auto x : temp){
                map1[x.first][u]=1;
                map2[x.first]++;
            }
        }
        cout<<res<<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>
using namespace std;
#define int long long int

signed main(){
    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        map<int,map<int,int>> map1;
        int maxi=0;int maxinode=0;
        map<int,int> map2;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            map1[u][v]=1;
            map1[v][u]=1;
            map2[u]++;map2[v]++;
            if(maxi<map2[u]){
                maxi=map2[u];
                maxinode=u;
            }
            if(maxi<map2[v]){
                maxi=map2[v];
                maxinode=v;
            }
        }
        int ans=maxi;
        for(auto x : map1[maxinode]){
            int v=x.first;
            map1[v].erase(maxinode);
            map2[v]--;
        }
        map1[maxinode].clear();
        map2.erase(maxinode);
        int maxi2=0;
        for(auto x : map2){
            maxi2=max(maxi2,x.second);
        }
        ans+=(maxi2-1);
        cout<<ans<<endl;
    }
    return 0;
}