ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

using namespace std;



typedef long long ll;



template<typename X, typename Y> bool ckmin(X& x , const Y& y ) { return (y < x) ? (x = y, 1) : 0; }

template<typename X, typename Y> bool ckmax(X& x , const Y& y ) { return (x < y) ? (x = y, 1) : 0; }



const int mx = 1e5+1;



bool can(ll sum , ll two, ll three) {

    if(sum%9 == 0) return true;

    if(two > 0) {

        if(can(sum + 2, two-1, three)) return true;

    }

    if(three > 0) {

        if(can(sum + 6, two, three-1)) return true;

    }



    return false;

}



void solve() {

    ll n;

    cin >> n;



    ll sum = 0;

    ll two = 0, three = 0;

    while(n != 0) {

        sum += n%10;

        if(n%10 == 2) two++;

        else if(n%10 == 3) three++;

        n/=10;

    }

    if(can(sum, two, three)) cout << "YES" << endl;

    else cout << "NO" << endl;



}

 

int main(){

    ios::sync_with_stdio(0);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    // solve();

    return 0;

}

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

using namespace std;



typedef long long ll;



template<typename X, typename Y> bool ckmin(X& x , const Y& y ) { return (y < x) ? (x = y, 1) : 0; }

template<typename X, typename Y> bool ckmax(X& x , const Y& y ) { return (x < y) ? (x = y, 1) : 0; }



const int mx = 1e5+1;



void solve() {

    ll n;

    cin >> n;



    ll sum = 0;

    ll two = 0, three = 0;

    while(n != 0) {

        sum += n%10;

        if(n%10 == 2) two++;

        else if(n%10 == 3) three++;

        n/=10;

    }

    

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

        for(int j = 0; j <= three; j++) {

            if((sum + 2*i + 6*j)%9 == 0) {

                cout << "YES" << endl;

                return;

            }

        }

    }

    cout << "NO" << endl;



}

 

int main(){

    ios::sync_with_stdio(0);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin >> t;

    while(t--){

        solve();

    }

    // solve();

    return 0;

}
Problem: 2057C - Trip to the Olympiad
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;
typedef vector<ll> v;
#define fi(k, n) for (ll i = k; i < n; i++)
#define fj(k, n) for (ll j = k; j < n; j++)
#define fx(k) for ( auto x : k )
#define fir(n, k) for (ll i = n; i <= k; i--)
#define l "\n"
#define Mx(a) *max_element(a.begin(),a.end())
#define Mn(a) *min_element(a.begin(),a.end())
#define sot(a) sort(a.begin(),a.end())
#define sotr(a) sort(a.begin(),a.end(),greater<int>());


ll n, m, k, x, y, o, p, u, ans, sum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error1.txt", "w", stderr);
#endif // ONLINE_JUDGE
    ll t;
    cin >> t;
    while (t--) {

        cin >> x >> y;
        v a(3);

        ans = 0;

        for (ll i = 35 ; i >= 0; i--) {
            o = (x & (1ll << i));
            p = (y & (1ll << i));
            if (o == p) {
                ans += (1ll << i) * p;
            }
            else {
                ans += (1ll << i);
                break;
            }
        }
        a[0] = ans;
        a[1] = a[0] - 1;
        a[2] = ans;

        cout << a[0] << ' ' << a[1] << ' ' << a[2] << l;

    }
    cerr << "Time elapsed: " << setprecision(6) << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef vector<ll> v;
#define fi(k, n) for (ll i = k; i < n; i++)
#define fj(k, n) for (ll j = k; j < n; j++)
#define fx(k) for ( auto x : k )
#define fir(n, k) for (ll i = n; i <= k; i--)
#define l "\n"
#define Mx(a) *max_element(a.begin(),a.end())
#define Mn(a) *min_element(a.begin(),a.end())
#define sot(a) sort(a.begin(),a.end())
#define sotr(a) sort(a.begin(),a.end(),greater<int>());


ll n, m, k, x, y, o, p, u, ans, sum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error1.txt", "w", stderr);
#endif // ONLINE_JUDGE
    ll t;
    cin >> t;
    while (t--) {

        cin >> x >> y;
        v a(3);

        ans = 0;

        for (ll i = 35 ; i >= 0; i--) {
            o = (x & (1ll << i));
            p = (y & (1ll << i));
            if (o == p) {
                ans += (1ll << i) * p;
            }
            else {
                ans += (1ll << i);
                break;
            }
        }
        a[0] = ans;
        a[1] = a[0] - 1;
        fi(x , y + 1) {
            if (i != a[0] && i != a[1]) {
                a[2] = i;
                break;
            }
        }

        cout << a[0] << ' ' << a[1] << ' ' << a[2] << l;

    }
    cerr << "Time elapsed: " << setprecision(6) << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
Problem: 2057C - Trip to the Olympiad
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;
typedef vector<ll> v;
#define fi(k, n) for (ll i = k; i < n; i++)
#define fj(k, n) for (ll j = k; j < n; j++)
#define fx(k) for ( auto x : k )
#define fir(n, k) for (ll i = n; i <= k; i--)
#define l "\n"
#define Mx(a) *max_element(a.begin(),a.end())
#define Mn(a) *min_element(a.begin(),a.end())
#define sot(a) sort(a.begin(),a.end())
#define sotr(a) sort(a.begin(),a.end(),greater<int>());


ll n, m, k, x, y, o, p, u, ans, sum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error1.txt", "w", stderr);
#endif // ONLINE_JUDGE
    ll t;
    cin >> t;
    while (t--) {

        cin >> x >> y;
        v a(3);

        ans = 0;

        for (ll i = 35 ; i >= 0; i--) {
            o = (x & (1ll << i));
            p = (y & (1ll << i));
            if (o == p) {
                ans += (1ll << i) * p;
            }
            else {
                ans += (1ll << i);
                break;
            }
        }
        a[0] = ans;
        a[1] = a[0] - 1;
        fi(x , y + 1) {
            if (i != a[0] && i != a[1]) {
                a[2] = i;
                break;
            }
        }

        cout << a[0] << ' ' << a[1] << ' ' << a[2] << l;

    }
    cerr << "Time elapsed: " << setprecision(6) << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef vector<ll> v;
#define fi(k, n) for (ll i = k; i < n; i++)
#define fj(k, n) for (ll j = k; j < n; j++)
#define fx(k) for ( auto x : k )
#define fir(n, k) for (ll i = n; i <= k; i--)
#define l "\n"
#define Mx(a) *max_element(a.begin(),a.end())
#define Mn(a) *min_element(a.begin(),a.end())
#define sot(a) sort(a.begin(),a.end())
#define sotr(a) sort(a.begin(),a.end(),greater<int>());


ll n, m, k, x, y, o, p, u, ans, sum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error1.txt", "w", stderr);
#endif // ONLINE_JUDGE
    ll t;
    cin >> t;
    while (t--) {

        cin >> x >> y;
        v a(3);

        ans = 0;

        for (ll i = 30 ; i >= 0; i--) {
            o = (x & (1ll << i));
            p = (y & (1ll << i));
            if (o == p) {
                ans += (1ll << i) * (o > 0) ;
            }
            else {
                ans += (1ll << i);
                break;
            }
        }
        a[0] = ans;
        a[1] = a[0] - 1;
        fi(x , y + 1) {
            if (i != a[0] && i != a[1]) {
                a[2] = i;
                break;
            }
        }

        cout << a[0] << ' ' << a[1] << ' ' << a[2] << l;

    }
    cerr << "Time elapsed: " << setprecision(6) << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
Problem: 2057C - Trip to the Olympiad
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;
typedef vector<ll> v;
#define fi(k, n) for (ll i = k; i < n; i++)
#define fj(k, n) for (ll j = k; j < n; j++)
#define fx(k) for ( auto x : k )
#define fir(n, k) for (ll i = n; i <= k; i--)
#define l "\n"
#define Mx(a) *max_element(a.begin(),a.end())
#define Mn(a) *min_element(a.begin(),a.end())
#define sot(a) sort(a.begin(),a.end())
#define sotr(a) sort(a.begin(),a.end(),greater<int>());


ll n, m, k, x, y, o, p, u, ans, sum;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    freopen("error1.txt", "w", stderr);
#endif // ONLINE_JUDGE
    ll t;
    cin >> t;
    while (t--) {

        cin >> x >> y;
        v a(3);

        ans = 0;

        for (ll i = 35 ; i >= 0; i--) {
            o = (x & (1ll << i));
            p = (y & (1ll << i));
            if (o == p) {
                ans += (1ll << i) * p;
            }
            else {
                ans += (1ll << i);
                break;
            }
        }
        a[0] = ans;
        a[1] = a[0] - 1;
        a[2] = ans;

        cout << a[0] << ' ' << a[1] << ' ' << a[2] << l;

    }
    cerr << "Time elapsed: " << setprecision(6) << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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


int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;


    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;

        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }
        if(a<=b){
            std::cout<<1<<"\n";
        }
        else{
            std::vector<int>arr2;

        int u=0;

        for(const auto& n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){ 
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
        }

}    return 0;
}

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

using i64 = long long;

void solve() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.end());
    std::vector<int> cnt = {1};
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            cnt.back()++;
        } else {
            cnt.emplace_back(1);
        }
    }
    std::sort(cnt.begin(), cnt.end());
    int m = cnt.size();
    for (int i = 0; i < m - 1; i++) {
        if (cnt[i] > k) {
            std::cout << m - i << "\n";
            return;
        }
        k -= cnt[i];
    }
    std::cout << 1 << "\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    std::cin >> t;

    while (t--) {
        solve();
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


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


int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;


    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;
        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }

        std::vector<int>arr2;
        for(auto n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
}    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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


int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;


    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;

        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }
        if(a<=b){
            std::cout<<1<<"\n";
        }
        else{
                    std::vector<int>arr2;
        for(auto n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){ 
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
        }

}    return 0;
}

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


int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;


    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;

        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }
        if(a<=b){
            std::cout<<1<<"\n";
        }
        else{
            std::vector<int>arr2;

        int u=0;

        for(const auto& n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){ 
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
        }

}    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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


int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;


    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;
        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }

        std::vector<int>arr2;
        for(auto n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
}    return 0;
}

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


int return1(long long int a , long long int b){
    if((a<0 && b<0 )|| (a>0 && b>0)){
        return 1;
    }
    if(a==0 && b==0){
        return 0;
    }
    return -1;
}

int main(){

    unsigned int testcase;
    std::cin>>testcase;


    while(testcase--){
        int a , b;
        std::unordered_map<long long int , long long int>arr;
        std::cin>>a>>b;

        for(int i=0;i<a;i++){
            long long int y;
            std::cin>>y;
            arr[y]++;
        }
        if(a<=b){
            std::cout<<1<<"\n";
        }
        else{
                    std::vector<int>arr2;
        for(auto n:arr){
            arr2.push_back(n.second);
        }

        std::sort(arr2.begin() , arr2.end());
        int counter=1;
        int i;
        for(i=0;i<arr2.size()-1; i++){
            if(b<arr2[i]){ 
                break;
            }
            b-=arr2[i];
        }
        std::cout<<counter+arr2.size()-1-i<<"\n";
        }

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

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<unordered_set<int>> adj(n + 1);
    map<int, int, less<int>> indeg; 
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);adj[v].insert(u);
        indeg[u]++; indeg[v]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (auto &[node, degree] : indeg) {
            if(node==i) continue;
            else if (adj[i].count(node) ) { 
                ans = max(ans, indeg[node] + indeg[i] - 2);
            } else { 
                ans = max(ans, indeg[node] + indeg[i] - 1);
            }
        }
    }
    cout << ans << endl;
}

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


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

void solve() {
    int n;
    cin >> n;
    
    vector<unordered_set<int>> adj(n + 1);
    vector<pair<int, int>> indeg; 
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].insert(v);
        adj[v].insert(u);
    }
    for (int i = 1; i <= n; i++) {
        indeg.push_back({(int)adj[i].size(), i});
    }
    sort(indeg.rbegin(), indeg.rend()); 
    int ans = 0;
    for (int i = 0; i <n; i++) {
        int node1 = indeg[i].second;
        for (int j = i + 1; j < n; j++) {
            int node2 = indeg[j].second;
            if (node1 == node2) continue;
            if (adj[node1].count(node2)) {
                ans = max(ans, indeg[i].first + indeg[j].first - 2);
            } else { 
                ans = max(ans, indeg[i].first + indeg[j].first - 1);
                break;
            }
        }
    }

    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T;
    cin >> T;
    while (T--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

void solve() {
    int n;
    cin >> n;
    
    vector<vector<int>> adj(n + 1);
    map<int, int> indeg;

    for (int i = 0; i < n - 1; i++) {
        int src, des;
        cin >> src >> des;
        adj[src].push_back(des);
        adj[des].push_back(src);
        indeg[src]++;
        indeg[des]++;
    }
    int maxi = -1, max_edges = -1;
    for (auto &[node, degree] : indeg) {
        if (degree > max_edges) {
            max_edges = degree;
            maxi = node;
        }
    }
    unordered_set<int> st;
    for (int node : adj[maxi]) {
        st.insert(node);
        indeg[node]--;
    }
    indeg[maxi] = 0;

    int maxi2 = -1, max_edges2 = -1;
    for (auto &[node, degree] : indeg) {
        if (degree > max_edges2) {
            max_edges2 = degree;
            maxi2 = node;
        }
    }
    cout << (max_edges + max_edges2 - 1) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T;
    cin >> T;
    while (T--) solve();
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)

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

void solve() {
    int n;
    cin >> n;
    
    vector<vector<int>> adj(n + 1);
    map<int, int> indeg;

    for (int i = 0; i < n - 1; i++) {
        int src, des;
        cin >> src >> des;
        adj[src].push_back(des);
        adj[des].push_back(src);
        indeg[src]++;
        indeg[des]++;
    }
    int maxi = -1, max_edges = -1;
    for (auto &[node, degree] : indeg) {
        if (degree > max_edges) {
            max_edges = degree;
            maxi = node;
        }
    }
    unordered_set<int> st;
    for (int node : adj[maxi]) {
        st.insert(node);
        indeg[node]--;
    }
    indeg[maxi] = 0;

    int maxi2 = -1, max_edges2 = -1;
    for (auto &[node, degree] : indeg) {
        if (degree > max_edges2) {
            max_edges2 = degree;
            maxi2 = node;
        }
    }
    cout << (max_edges + max_edges2 - 1) << endl;
}

int main() {
    ios_base::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>
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> adj(n + 1);
    vector<int> indeg(n + 1, 0);
    for (int i = 0; i < n - 1; i++) {
        int src, des;
        cin >> src >> des;
        adj[src].push_back(des);
        adj[des].push_back(src);
        indeg[src]++;
        indeg[des]++;
    }
    int maxi = -1, max_edges = -1;
    for (int i = 1; i <= n; i++) {
        if (indeg[i] > max_edges) {
            max_edges = indeg[i];
            maxi = i;
        }
    }
    if (max_edges == 1) {
        cout << max(0, n - 2) << endl;
        return;
    }
    unordered_set<int> st;
    for (int node : adj[maxi]) {
        st.insert(node);
        indeg[node]--;
    }
    indeg[maxi] = 0;
    int maxi2 = -1, max_edges2 = -1;
    for (int i = 1; i <= n; i++) {
        if (indeg[i] > max_edges2 && !st.count(i)) {
            max_edges2 = indeg[i];
            maxi2 = i;
        }
    }
    cout << (max_edges + max_edges2 - 1) << endl;
}

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