243852026-02-10 20:26:38abcdTom és Jerry 3cpp17Runtime error 41/5071ms2100 KiB
#include <bits/stdc++.h>
using namespace std;

/*
3
4 1 3 1
1 2 1 3 3 4
5 2 5 1 1 2 1 3 3 4 4 5
4 4 2 2 1 4 1 2 1 3
*/

const int maxn=20001;
vector<int> adj[maxn];

void bfs(int start, vector<int>& d, int n){
    fill(d.begin(), d.begin()+n+1, -1);
    queue<int> q;
    q.push(start);
    d[start]=0;
    while(!q.empty()){
        int v=q.front(); q.pop();
        for(int to:adj[v]){
            if(d[to]==-1){
                d[to]=d[v]+1;
                q.push(to);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int t;cin>>t;
    while(t--){
        int n,ts,js,k;cin>>n>>ts>>js>>k;
        vector<int> dt(n+1),dj(n+1),da(n+1);
        for(int i=1;i<=n;i++) adj[i].clear();
        for(int i=1;i<n;i++){
            int a,b;cin>>a>>b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        bfs(ts, dt, n);
        bfs(js, dj, n);
        bool yes=false;
        for(int i=1;i<=n;i++){
            if(dj[i]<k && dt[i]>k) yes=true;
        }
        if(!yes){
            cout<<"IGEN\n"; continue;
        }
        int a=1;
        for(int i=1;i<=n;i++){
            if(dt[i]>dt[a]) a=i;
        }
        bfs(a, da, n);
        int mx=0;
        for(int i=1;i<=n;i++){
            mx=max(mx, da[i]);
        }
        if(mx>k*2) cout<<"NEM\n";
        else cout<<"IGEN\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base41/50
1Accepted0/01ms820 KiB
2Accepted0/01ms820 KiB
3Accepted5/51ms820 KiB
4Accepted1/12ms820 KiB
5Accepted1/12ms828 KiB
6Accepted1/12ms820 KiB
7Accepted1/12ms820 KiB
8Accepted1/13ms820 KiB
9Accepted1/12ms820 KiB
10Accepted1/12ms864 KiB
11Accepted2/22ms820 KiB
12Accepted2/22ms1004 KiB
13Accepted1/12ms820 KiB
14Accepted2/268ms1776 KiB
15Accepted2/259ms1416 KiB
16Accepted2/268ms1844 KiB
17Runtime error0/22ms1076 KiB
18Accepted2/271ms1760 KiB
19Accepted2/268ms1844 KiB
20Runtime error0/22ms1076 KiB
21Accepted2/257ms1332 KiB
22Accepted2/259ms1332 KiB
23Runtime error0/32ms1092 KiB
24Accepted2/270ms1756 KiB
25Accepted3/368ms2100 KiB
26Runtime error0/22ms1076 KiB
27Accepted2/261ms1332 KiB
28Accepted3/363ms1568 KiB