14242022-09-10 18:16:09kidesoTom és Jerry 3cpp17Runtime error 41/50167ms7460 KiB
#include <iostream>
#include <queue>

using namespace std;

const int maxN = 20001;
vector<int> x[maxN];
int tav[maxN][3];
bool l[maxN][3];
int N, K, i, a, b, T, J, s, m, tipus;
bool jo;

void mely(int p){
    l[p][tipus] = true;

    for(auto index : x[p])
        if(!l[index][tipus]){
            tav[index][tipus] = tav[p][tipus] + 1;
            mely(index);
        }
}

void ujra(int N){
    for(i = 1; i <= N; ++i){
        tav[i][0] = tav[i][1] = tav[i][2] = 0;
        l[i][0] = l[i][1] = l[i][2] = false;
        x[i].clear();
    }
}

void megold(){
    cin >> N >> T >> J >> K;

    for(i = 1; i < N; ++i){
        cin >> a >> b;
        x[a].push_back(b);
        x[b].push_back(a);
    }

    tipus = 0;
    mely(T); 
    tipus = 1;
    mely(J);

    s = 0;
    m = 0;
    for(i = 1; i <= N; ++i)
        if(m < tav[i][0]){
            m = tav[i][0];
            s = i;
        }

    tipus = 2;
    mely(s);
    m = 0;

    for(i = 1; i <= N; ++i)
        m = max(m, tav[i][2]);

    jo = true;
    for(i = 1; i <= N; ++i)
        if(tav[i][0] > tav[i][1] + 1 && tav[i][0] > K)
            jo = false;

    cout << ((jo || m <= 2 * K) ? "IGEN\n" : "NEM\n");
    ujra(N);
}

int main(){
    int t;
    cin >> t;

    while(t--)
        megold();

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base41/50
1Accepted0/03ms3144 KiB
2Accepted0/03ms3396 KiB
3Accepted5/53ms3668 KiB
4Accepted1/13ms3784 KiB
5Accepted1/13ms3936 KiB
6Accepted1/13ms4092 KiB
7Accepted1/13ms4284 KiB
8Accepted1/13ms4144 KiB
9Accepted1/13ms4208 KiB
10Accepted1/13ms4468 KiB
11Accepted2/23ms4420 KiB
12Accepted2/23ms4420 KiB
13Accepted1/13ms4424 KiB
14Accepted2/2167ms6776 KiB
15Accepted2/2144ms5872 KiB
16Accepted2/2165ms6868 KiB
17Runtime error0/22ms4720 KiB
18Accepted2/2167ms6972 KiB
19Accepted2/2162ms7400 KiB
20Runtime error0/22ms4956 KiB
21Accepted2/2144ms6076 KiB
22Accepted2/2142ms6324 KiB
23Runtime error0/32ms4924 KiB
24Accepted2/2166ms7040 KiB
25Accepted3/3162ms7460 KiB
26Runtime error0/22ms4884 KiB
27Accepted2/2145ms6036 KiB
28Accepted3/3142ms6248 KiB