92122024-02-18 16:38:39FarkasZénóTúra (75 pont)python3Time limit exceeded 71/75490ms58600 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
base71/75
1Accepted0/021ms12184 KiB
2Accepted0/021ms12476 KiB
3Accepted6/621ms12464 KiB
4Accepted3/345ms13496 KiB
5Accepted3/343ms13924 KiB
6Accepted4/443ms14096 KiB
7Accepted4/445ms13952 KiB
8Accepted4/443ms14388 KiB
9Accepted2/2270ms21540 KiB
10Accepted2/2270ms21752 KiB
11Accepted2/2277ms21644 KiB
12Accepted2/2270ms21640 KiB
13Accepted2/2275ms21752 KiB
14Accepted3/3266ms22080 KiB
15Accepted2/2270ms21776 KiB
16Accepted2/2268ms22072 KiB
17Accepted2/2268ms22268 KiB
18Accepted2/2268ms22312 KiB
19Accepted3/3268ms22352 KiB
20Accepted2/2272ms22268 KiB
21Accepted2/2280ms23328 KiB
22Accepted3/3282ms22636 KiB
23Time limit exceeded0/2460ms47160 KiB
24Time limit exceeded0/2490ms43460 KiB
25Accepted2/2368ms55072 KiB
26Accepted2/2351ms57232 KiB
27Accepted2/2333ms55332 KiB
28Accepted2/2354ms56636 KiB
29Accepted2/2375ms56868 KiB
30Accepted2/2361ms57008 KiB
31Accepted2/2377ms58600 KiB
32Accepted2/2398ms57576 KiB