14262022-09-10 18:21:25kidesoTom és Jerry 3cpp17Accepted 50/50172ms9360 KiB
#include <iostream>
#include <queue>

using namespace std;

const int maxN = 30001;
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 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");

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

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

    while(t--)
        megold();

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/04ms3416 KiB
2Accepted0/03ms3572 KiB
3Accepted5/53ms3636 KiB
4Accepted1/14ms3640 KiB
5Accepted1/14ms3932 KiB
6Accepted1/14ms3844 KiB
7Accepted1/14ms4100 KiB
8Accepted1/14ms4044 KiB
9Accepted1/14ms4304 KiB
10Accepted1/14ms4600 KiB
11Accepted2/24ms4412 KiB
12Accepted2/24ms4564 KiB
13Accepted1/14ms4724 KiB
14Accepted2/2171ms6928 KiB
15Accepted2/2146ms5848 KiB
16Accepted2/2172ms6864 KiB
17Accepted2/2165ms7700 KiB
18Accepted2/2172ms6840 KiB
19Accepted2/2167ms7336 KiB
20Accepted2/2115ms9360 KiB
21Accepted2/2149ms6420 KiB
22Accepted2/2143ms6776 KiB
23Accepted3/3164ms9032 KiB
24Accepted2/2172ms7876 KiB
25Accepted3/3165ms8124 KiB
26Accepted2/2172ms8904 KiB
27Accepted2/2148ms6948 KiB
28Accepted3/3143ms7276 KiB