13802022-08-30 11:12:07TusySamuTom és Jerry 3cpp17Wrong answer 2/50171ms7844 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, ts, js, k, ma, ma2, a, b;
        cin >> n >> ts >> js >> k;
        vector<vector<int> > x(n+1);
        vector<int> tavt(n+1, -1), tavj(n+1, -1);
        for (int i=0; i<n-1; i++) {
            cin >> a >> b;
            x[a].push_back(b);
            x[b].push_back(a);
        }
        queue<int> q;
        q.push(ts);
        tavt[ts]=0;
        while (!q.empty()) {
            a=q.front();
            q.pop();
            for (int cs : x[a]) {
                if (tavt[cs]==-1) {
                    tavt[cs]=tavt[a]+1;
                    q.push(cs);
                    if (ma<tavt[cs]) {
                        ma2=ma;
                        ma=tavt[cs];
                    }
                    else ma2=max(ma2, tavt[cs]);
                }
            }
        }
        q.push(js);
        tavj[js]=0;
        while (!q.empty()) {
            a=q.front();
            q.pop();
            for (int cs : x[a]) {
                if (tavj[cs]==-1) {
                    tavj[cs]=tavt[a]+1;
                    q.push(cs);
                }
            }
        }
        a=0;
        for (int i=1; (i<=n && !a); i++) {
            if (tavj[i]<=k && tavt[i]>k) a=1;
        }
        if (a==0 || ma+ma2<=k) cout << "IGEN\n";
        else cout << "NEM\n";
    }
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/03ms1812 KiB
2Wrong answer0/02ms2068 KiB
3Wrong answer0/52ms2260 KiB
4Accepted1/13ms2508 KiB
5Wrong answer0/13ms2700 KiB
6Wrong answer0/13ms2904 KiB
7Wrong answer0/13ms3076 KiB
8Accepted1/13ms3280 KiB
9Wrong answer0/13ms3308 KiB
10Wrong answer0/13ms3444 KiB
11Wrong answer0/23ms3540 KiB
12Wrong answer0/23ms3512 KiB
13Wrong answer0/13ms3752 KiB
14Wrong answer0/2170ms6252 KiB
15Wrong answer0/2158ms4984 KiB
16Wrong answer0/2170ms6260 KiB
17Wrong answer0/2157ms7788 KiB
18Wrong answer0/2171ms6568 KiB
19Wrong answer0/2170ms6636 KiB
20Wrong answer0/2107ms7812 KiB
21Wrong answer0/2158ms5272 KiB
22Wrong answer0/2157ms5304 KiB
23Wrong answer0/3157ms7656 KiB
24Wrong answer0/2171ms6696 KiB
25Wrong answer0/3170ms6684 KiB
26Wrong answer0/2158ms7844 KiB
27Wrong answer0/2158ms5388 KiB
28Wrong answer0/3158ms5412 KiB