72502024-01-05 14:16:24anonTom és Jerry 3cpp17Időlimit túllépés 17/50800ms11556 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++) {
            tree = vector<Branch>(N + 1);
            build_tree(i, -1, 0, tree, graph);
            ok = (tree[i].md <= K);
        }
        cout << (ok ? "IGEN" : "NEM") << '\n';
    }
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base17/50
1Elfogadva0/03ms1828 KiB
2Elfogadva0/04ms2176 KiB
3Elfogadva5/53ms2236 KiB
4Elfogadva1/14ms2616 KiB
5Elfogadva1/112ms2672 KiB
6Elfogadva1/17ms2856 KiB
7Elfogadva1/110ms2960 KiB
8Elfogadva1/14ms2820 KiB
9Elfogadva1/114ms2816 KiB
10Elfogadva1/114ms3140 KiB
11Elfogadva2/24ms3332 KiB
12Elfogadva2/214ms3356 KiB
13Elfogadva1/113ms3600 KiB
14Időlimit túllépés0/2800ms7480 KiB
15Időlimit túllépés0/2759ms5292 KiB
16Időlimit túllépés0/2774ms7564 KiB
17Időlimit túllépés0/2767ms10056 KiB
18Időlimit túllépés0/2726ms7804 KiB
19Időlimit túllépés0/2754ms7748 KiB
20Időlimit túllépés0/2741ms11556 KiB
21Időlimit túllépés0/2754ms5844 KiB
22Időlimit túllépés0/2764ms6008 KiB
23Időlimit túllépés0/3771ms10664 KiB
24Időlimit túllépés0/2762ms8212 KiB
25Időlimit túllépés0/3767ms8124 KiB
26Időlimit túllépés0/2774ms10588 KiB
27Időlimit túllépés0/2768ms6032 KiB
28Időlimit túllépés0/3767ms6120 KiB