14252022-09-10 18:19:41kidesoTom és Jerry 3cpp17Runtime error 41/50171ms7708 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 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
base41/50
1Accepted0/03ms2736 KiB
2Accepted0/03ms2904 KiB
3Accepted5/53ms3172 KiB
4Accepted1/14ms3384 KiB
5Accepted1/14ms3584 KiB
6Accepted1/14ms3788 KiB
7Accepted1/14ms4080 KiB
8Accepted1/13ms3868 KiB
9Accepted1/13ms3868 KiB
10Accepted1/14ms3760 KiB
11Accepted2/23ms3752 KiB
12Accepted2/23ms4044 KiB
13Accepted1/14ms4188 KiB
14Accepted2/2170ms6436 KiB
15Accepted2/2146ms5448 KiB
16Accepted2/2170ms6532 KiB
17Runtime error0/23ms4452 KiB
18Accepted2/2171ms6772 KiB
19Accepted2/2165ms7132 KiB
20Runtime error0/22ms4724 KiB
21Accepted2/2145ms5832 KiB
22Accepted2/2143ms6284 KiB
23Runtime error0/32ms5080 KiB
24Accepted2/2171ms7244 KiB
25Accepted3/3165ms7708 KiB
26Runtime error0/23ms5108 KiB
27Accepted2/2146ms6524 KiB
28Accepted3/3143ms6592 KiB