70232023-12-27 15:07:06horvathabelTom és Jerry 3cpp11Wrong answer 0/50172ms7436 KiB
#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n,jk,tk,k;
    cin>>n>>jk>>tk>>k;
    vector<vector<int>> g;
    g.resize(n+1,vector<int>());
    for (int i=0; i<n-1;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> jt;
    jt.resize(n+1,0);
    queue<int> q;
    q.push(jk);
    vector<bool> seen;
    seen.resize(n+1,0);
    seen[jk]=true;
    while (!q.empty()){
        int v=q.front();
        q.pop();
        for (int edge:g[v]){
            if (!seen[edge]){
                seen[edge]=true;
                jt[edge]=jt[v]+1;
                q.push(edge);
            }
        }
    }

    vector<int> tt;
    tt.resize(n+1,0);
    seen.clear();
    seen.resize(n+1,0);
    seen[tk]=true;
    q.push(tk);
    while (!q.empty()){
        int v=q.front();
        q.pop();
        for (int edge:g[v]){
            if (!seen[edge]){
                seen[edge]=true;
                tt[edge]=tt[v]+1;
                q.push(edge);
            }
        }
    }
    int ans=0;
    for (int i=1; i<=n;i++){
        if (jt[i]<tt[i]-1){
            ans=max(ans,tt[i]-1);
        }
    }
    cout<<(ans<k? "IGEN":"NEM")<<"\n";
}
int main()
{
    int t;
    cin>>t;
    while (t--) solve();
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1812 KiB
2Wrong answer0/03ms2016 KiB
3Wrong answer0/53ms2240 KiB
4Wrong answer0/14ms2364 KiB
5Wrong answer0/14ms2536 KiB
6Wrong answer0/14ms2664 KiB
7Wrong answer0/14ms2692 KiB
8Wrong answer0/14ms2932 KiB
9Wrong answer0/14ms3032 KiB
10Wrong answer0/14ms3116 KiB
11Wrong answer0/24ms3116 KiB
12Wrong answer0/24ms3112 KiB
13Wrong answer0/14ms3112 KiB
14Wrong answer0/2172ms5756 KiB
15Wrong answer0/2160ms4416 KiB
16Wrong answer0/2172ms5776 KiB
17Wrong answer0/2162ms7144 KiB
18Wrong answer0/2171ms5948 KiB
19Wrong answer0/2171ms5920 KiB
20Wrong answer0/2108ms7360 KiB
21Wrong answer0/2160ms4688 KiB
22Wrong answer0/2164ms4792 KiB
23Wrong answer0/3159ms7432 KiB
24Wrong answer0/2172ms6252 KiB
25Wrong answer0/3172ms6128 KiB
26Wrong answer0/2163ms7436 KiB
27Wrong answer0/2160ms4952 KiB
28Wrong answer0/3160ms5012 KiB