67192023-12-17 20:10:16111Tom és Jerry 3cpp17Wrong answer 6/50108ms9264 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double

#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef CB
	freopen("be2.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	int T;
	cin >> T;
	while (T--) {
		int N, TS, JS, K;
		cin >> N >> TS >> JS >> K;
		vector<vector<int>> g(N + 1);
		for (int i = 0; i < N - 1; i++) {
			int a, b;
			cin >> a >> b;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		deque<int> q;
		vector<int> td(N + 1, -1);
		td[TS] = 0;
		q.push_back(TS);
		while (!q.empty()) {
			int i = q.front();
			q.pop_front();
			for (int j : g[i]) {
				if (td[j] == -1) {
					td[j] = td[i] + 1;
					q.push_back(j);
				}
			}
		}
		vector<int> jd(N + 1, -1);
		jd[JS] = 0;
		q.push_back(JS);
		while (!q.empty()) {
			int i = q.front();
			q.pop_front();
			for (int j : g[i]) {
				if (jd[j] == -1) {
					jd[j] = jd[i] + 1;
					q.push_back(j);
				}
			}
		}
		int s = 0;
		for (int i = 1; i <= N; i++) {
			if (jd[i] < td[i] + 1) {
				s = max(s, td[i]);
			}
		}
		if (s <= K + 1) {
			cout << "IGEN" << '\n';
			continue;
		}
		auto solve = [&](int i) {
			vector<int> v(N + 1, -1);
			deque<int> q;
			q.push_back(i);
			v[i] = 0;
			int f;
			while (!q.empty()) {
				int j = f = q.front();
				q.pop_front();
				for (int k : g[j]) {
					if (v[k] == -1) {
						v[k] = v[j] + 1;
						q.push_back(k);
					}
				}
			}
			return pii{f, v[f]};
		};
		auto [a, b] = solve(1);
		auto [c, d] = solve(a);
		if ((d + 1) / 2 <= K) {
			cout << "IGEN" << '\n';
			continue;
		}
		cout << "NEM" << '\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1832 KiB
2Accepted0/03ms2024 KiB
3Wrong answer0/53ms2232 KiB
4Wrong answer0/13ms2752 KiB
5Wrong answer0/14ms2880 KiB
6Wrong answer0/13ms2924 KiB
7Wrong answer0/14ms3144 KiB
8Wrong answer0/14ms3236 KiB
9Wrong answer0/13ms3436 KiB
10Wrong answer0/13ms3496 KiB
11Wrong answer0/24ms3688 KiB
12Wrong answer0/23ms3776 KiB
13Wrong answer0/13ms3776 KiB
14Wrong answer0/2108ms7348 KiB
15Wrong answer0/293ms5844 KiB
16Wrong answer0/2103ms7948 KiB
17Wrong answer0/297ms9264 KiB
18Accepted2/2107ms7656 KiB
19Accepted2/2105ms7724 KiB
20Accepted2/265ms9204 KiB
21Wrong answer0/293ms6204 KiB
22Wrong answer0/296ms6296 KiB
23Wrong answer0/392ms8904 KiB
24Wrong answer0/2103ms8040 KiB
25Wrong answer0/3104ms7868 KiB
26Wrong answer0/294ms9196 KiB
27Wrong answer0/297ms6288 KiB
28Wrong answer0/398ms6192 KiB