243762026-02-10 18:50:26abcdTom és Jerry 3cpp17Wrong answer 13/50156ms1868 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 dfs(int v,int pa,int dis,vector<int>& d){
    d[v]=dis;
    for(int to:adj[v]){
        if(to!=pa)dfs(to,v,dis+1,d);
    }
}

int main(){
    int t;cin>>t;
    while(t--){
        int n,ts,js,k;cin>>n>>ts>>js>>k;
        vector<int> dt(maxn),dj(maxn),da(maxn);
        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);
        }
        dfs(ts,-1,0,dt);
        dfs(js,-1,0,dj);
        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;
        }
        dfs(a,-1,0,da);
        int mx=0;
        for(int i=1;i<=n;i++){
            mx=max(mx,da[i]);
        }
        if(mx/2>k)cout<<"NEM\n";
        else cout<<"IGEN\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base13/50
1Accepted0/02ms1080 KiB
2Accepted0/02ms1076 KiB
3Wrong answer0/52ms1076 KiB
4Accepted1/13ms1260 KiB
5Wrong answer0/13ms1084 KiB
6Wrong answer0/13ms1076 KiB
7Wrong answer0/13ms916 KiB
8Wrong answer0/13ms1108 KiB
9Wrong answer0/13ms1080 KiB
10Wrong answer0/13ms1076 KiB
11Wrong answer0/23ms1268 KiB
12Wrong answer0/23ms1112 KiB
13Wrong answer0/13ms1076 KiB
14Wrong answer0/2155ms1868 KiB
15Wrong answer0/2134ms1332 KiB
16Accepted2/2152ms1740 KiB
17Runtime error0/22ms1268 KiB
18Accepted2/2156ms1848 KiB
19Accepted2/2153ms1844 KiB
20Runtime error0/22ms1268 KiB
21Wrong answer0/2134ms1332 KiB
22Accepted2/2133ms1588 KiB
23Runtime error0/32ms1076 KiB
24Accepted2/2152ms1844 KiB
25Wrong answer0/3152ms1844 KiB
26Runtime error0/22ms1268 KiB
27Accepted2/2135ms1460 KiB
28Wrong answer0/3135ms1588 KiB