72492024-01-05 13:39:22anonTom és Jerry 3cpp17Time limit exceeded 17/50800ms10984 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
typedef struct {
    ll md;
    ll depth;
    ll parent;
    vector<ll> children;
} Branch;
ll build_tree(ll vertex, ll parent, ll depth, vector<Branch> &tree, const vector<vector<ll>> &graph) {
    tree[vertex].md = depth;
    tree[vertex].depth = depth;
    tree[vertex].parent = parent;
    for(const auto &x : graph[vertex]) {
        if(x == parent)
            continue;
        tree[vertex].md = max(tree[vertex].md, build_tree(x, vertex, depth + 1, tree, graph));
        tree[vertex].children.push_back(x);
    }
    return tree[vertex].md;
}
bool does_tom_win(ll J, ll K, const vector<Branch> &tree) {
    ll rj;
    rj = J;
    while(rj != -1) {
        if(tree[J].depth - tree[rj].depth >= tree[rj].depth - 1)
            return true;
        if(tree[rj].depth + min(K - 1 - (tree[J].depth - tree[rj].depth), tree[rj].md - tree[rj].depth) > K)
            return false;
        rj = tree[rj].parent;
    }
    return true;
}
int main() {
    FastIO;
    bool ok;
    ll i, j, u, v, N, T, J, K, C;
    cin >> C;
    while(C--) {
        cin >> N >> T >> J >> K;
        vector<vector<ll>> graph(N + 1);
        for(i = 1; i < N; i++) {
            cin >> u >> v;
            graph[u].push_back(v);
            graph[v].push_back(u);
        }
        vector<Branch> tree(N + 1);
        build_tree(T, -1, 0, tree, graph);
        ok = does_tom_win(J, K, tree);
        for(i = 1; i <= N && !ok; i++) {
            ok = true;
            tree = vector<Branch>(N + 1);
            build_tree(i, -1, 0, tree, graph);
            for(j = 1; j <= N && ok; j++)
                ok = does_tom_win(j, K, tree);
        }
        cout << (ok ? "IGEN" : "NEM") << '\n';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base17/50
1Accepted0/03ms1832 KiB
2Accepted0/04ms2208 KiB
3Accepted5/53ms2272 KiB
4Accepted1/14ms2632 KiB
5Accepted1/112ms2816 KiB
6Accepted1/17ms3136 KiB
7Accepted1/110ms3264 KiB
8Accepted1/14ms3124 KiB
9Accepted1/114ms3128 KiB
10Accepted1/114ms3404 KiB
11Accepted2/24ms3280 KiB
12Accepted2/214ms3244 KiB
13Accepted1/113ms3232 KiB
14Time limit exceeded0/2800ms6948 KiB
15Time limit exceeded0/2771ms4864 KiB
16Time limit exceeded0/2763ms7140 KiB
17Time limit exceeded0/2763ms9468 KiB
18Time limit exceeded0/2774ms7208 KiB
19Time limit exceeded0/2768ms7160 KiB
20Time limit exceeded0/2767ms10984 KiB
21Time limit exceeded0/2763ms5156 KiB
22Time limit exceeded0/2769ms5392 KiB
23Time limit exceeded0/3739ms10004 KiB
24Time limit exceeded0/2763ms7768 KiB
25Time limit exceeded0/3763ms7832 KiB
26Time limit exceeded0/2763ms10416 KiB
27Time limit exceeded0/2763ms5516 KiB
28Time limit exceeded0/3726ms5544 KiB