13842022-08-30 12:02:15mraronTom és Jerry 3cpp17Elfogadva 50/5096ms17176 KiB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ins insert

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

const int MAXN=200001;

int n,t,j,k;
vector<int> adj[MAXN];
vector<int> distt, distj;

vector<int> bfs(int x) {
	vector<int> dist(n+1, -1);
	
	queue<pair<int,int>> q;
	q.push({x, 0});
	dist[x]=0;
	
	while(!q.empty()) {
		auto akt=q.front();q.pop();
		for(auto i:adj[akt.first]) {
			if(dist[i]==-1) {
				dist[i]=akt.yy+1;
				q.push({i, dist[i]});
			}
		}
	}
	
	return dist;
}

int vis[MAXN];
int explore(int jerry) {
	if(distj[jerry]>=distt[jerry]-1 || vis[jerry]) return -1;
	vis[jerry]=1;
	
	int mx=distt[jerry];
	for(auto i:adj[jerry]) {
		mx=max(mx, explore(i));
	}
	
	return mx;
}

int main() {
	IO;
	int T;
	cin>>T;
	while(T--) {
		cin>>n>>t>>j>>k;
		for(int i=1;i<=n;++i) {
			adj[i].clear();
			vis[i]=0;
		}
		
		for(int i=1;i<n;++i) {
			int a,b;
			cin>>a>>b;
			adj[a].pb(b);
			adj[b].pb(a);
		}
		
		
		vector<int> dist1=bfs(1);
		int furthest=max_element(all(dist1))-dist1.begin();
		vector<int> distf=bfs(furthest);
		int diameter=*max_element(all(distf));
				
		bool can_catch=false;
		can_catch|=diameter<=2*k;
		
		distt=bfs(t);
		distj=bfs(j);
		
		int mx=explore(j);
		can_catch|=mx<=k;
		
		cout<<(can_catch?"IGEN":"NEM")<<"\n";
	}
	
	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/06ms11252 KiB
2Elfogadva0/06ms11524 KiB
3Elfogadva5/56ms11724 KiB
4Elfogadva1/16ms12004 KiB
5Elfogadva1/16ms12072 KiB
6Elfogadva1/16ms12276 KiB
7Elfogadva1/17ms12520 KiB
8Elfogadva1/16ms12724 KiB
9Elfogadva1/17ms13000 KiB
10Elfogadva1/17ms12944 KiB
11Elfogadva2/27ms13008 KiB
12Elfogadva2/27ms13156 KiB
13Elfogadva1/16ms13256 KiB
14Elfogadva2/292ms15596 KiB
15Elfogadva2/282ms14592 KiB
16Elfogadva2/296ms15820 KiB
17Elfogadva2/293ms16956 KiB
18Elfogadva2/292ms15756 KiB
19Elfogadva2/294ms16132 KiB
20Elfogadva2/268ms16904 KiB
21Elfogadva2/282ms14644 KiB
22Elfogadva2/281ms14892 KiB
23Elfogadva3/393ms17176 KiB
24Elfogadva2/290ms16072 KiB
25Elfogadva3/390ms16356 KiB
26Elfogadva2/292ms17104 KiB
27Elfogadva2/279ms15012 KiB
28Elfogadva3/378ms15404 KiB