14222022-09-10 18:05:55kidesoTom és Jerry 3cpp17Wrong answer 1/50167ms7324 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;
bool jo;

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

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

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);
    }

    mely(T, 0); mely(J, 1);

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

    mely(s, 2);
    m = 0;

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

    if(m > 2 * K)
        jo = false;
    else{
        jo = true;

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

    cout << (jo ? "IGEN\n" : "NEM\n");
    ujra(N);
}

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

    while(t--)
        megold();

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/03ms2864 KiB
2Wrong answer0/03ms3148 KiB
3Wrong answer0/53ms3344 KiB
4Accepted1/14ms3560 KiB
5Wrong answer0/14ms3736 KiB
6Wrong answer0/13ms3624 KiB
7Wrong answer0/14ms3892 KiB
8Wrong answer0/14ms4116 KiB
9Wrong answer0/13ms3912 KiB
10Wrong answer0/14ms4176 KiB
11Wrong answer0/23ms4104 KiB
12Wrong answer0/23ms4228 KiB
13Wrong answer0/13ms4504 KiB
14Wrong answer0/2166ms6700 KiB
15Wrong answer0/2145ms5796 KiB
16Wrong answer0/2165ms6776 KiB
17Runtime error0/22ms4620 KiB
18Wrong answer0/2167ms6820 KiB
19Wrong answer0/2160ms7136 KiB
20Runtime error0/22ms4664 KiB
21Wrong answer0/2150ms6072 KiB
22Wrong answer0/2141ms6328 KiB
23Runtime error0/33ms4940 KiB
24Wrong answer0/2167ms7116 KiB
25Wrong answer0/3160ms7324 KiB
26Runtime error0/23ms4980 KiB
27Wrong answer0/2145ms6204 KiB
28Wrong answer0/3142ms6336 KiB