92112024-02-18 16:37:57FarkasZénóTúra (75 pont)python3Time limit exceeded 67/75460ms88140 KiB
from sys import stdin
from collections import defaultdict

def csunyakereso(graf, csunyak, indulas):
	for szomszed in graf[indulas]:
		ut = (indulas, szomszed)
		if szomszed in csunyak:
			print('NEM')
			print(2)
			print(indulas, szomszed)
			return True
		for masodik_szomszed in graf[szomszed]:
			if masodik_szomszed == indulas:
				continue
			if masodik_szomszed in csunyak:
				print('NEM')
				print(3)
				print(indulas, szomszed, masodik_szomszed)
				return True
	return False

T = int(stdin.readline())
for _ in range(T):
	N = int(stdin.readline())
	utak = defaultdict(set)
	sz = [int(x) for x in stdin.readline().split()]
	csunyak = set(i+1 for i, x in enumerate(sz) if x == -1)
	if len(csunyak) < 2:
		for _ in range(N-1):
			stdin.readline()
		print('IGEN')
		continue
	for _ in range(N-1):
		honnan, hova = [int(x) for x in stdin.readline().split()]
		utak[honnan].add(hova)
		utak[hova].add(honnan)
	for indulas in csunyak:
		if csunyakereso(utak, csunyak, indulas):
			break
	else:
		print('IGEN')
	# print(sz)
	# print(csunyak)
	# print(utak)
SubtaskSumTestVerdictTimeMemory
base67/75
1Accepted0/020ms12116 KiB
2Accepted0/020ms12764 KiB
3Accepted6/619ms12524 KiB
4Accepted3/345ms13864 KiB
5Accepted3/345ms13880 KiB
6Accepted4/443ms14164 KiB
7Accepted4/445ms14276 KiB
8Accepted4/443ms14508 KiB
9Accepted2/2266ms21216 KiB
10Accepted2/2270ms21488 KiB
11Accepted2/2270ms21596 KiB
12Accepted2/2272ms22012 KiB
13Accepted2/2272ms22232 KiB
14Accepted3/3263ms22008 KiB
15Accepted2/2279ms22380 KiB
16Accepted2/2270ms22676 KiB
17Accepted2/2270ms22476 KiB
18Accepted2/2272ms22276 KiB
19Accepted3/3270ms22212 KiB
20Accepted2/2264ms22384 KiB
21Accepted2/2273ms22860 KiB
22Accepted3/3280ms23084 KiB
23Time limit exceeded0/2460ms47204 KiB
24Time limit exceeded0/2423ms88140 KiB
25Accepted2/2335ms55180 KiB
26Accepted2/2331ms56940 KiB
27Accepted2/2365ms54672 KiB
28Accepted2/2324ms56912 KiB
29Accepted2/2338ms57000 KiB
30Accepted2/2358ms57008 KiB
31Time limit exceeded0/2409ms58836 KiB
32Time limit exceeded0/2435ms57300 KiB