92102024-02-18 16:28:14FarkasZénóTúra (75 pont)python3Time limit exceeded 67/75479ms58720 KiB
from sys import stdin
from collections import defaultdict

def csunyakereso(graf, csunyak, eddigi_ut):
	mehet_tovabb = len(eddigi_ut) < 2
	for kovetkezo in graf[eddigi_ut[-1]]:
		if kovetkezo in eddigi_ut:
			continue
		if kovetkezo in csunyak:
			print('NEM')
			print(len(eddigi_ut)+1)
			print(' '.join(str(x) for x in eddigi_ut + (kovetkezo,)))
			return True
		if mehet_tovabb:
			if csunyakereso(graf, csunyak, eddigi_ut + (kovetkezo,)):
				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 cs in csunyak:
		if csunyakereso(utak, csunyak, (cs,)):
			break
	else:
		print('IGEN')
	# print(sz)
	# print(csunyak)
	# print(utak)
SubtaskSumTestVerdictTimeMemory
base67/75
1Accepted0/021ms11880 KiB
2Accepted0/021ms12652 KiB
3Accepted6/620ms12816 KiB
4Accepted3/345ms13636 KiB
5Accepted3/343ms13980 KiB
6Accepted4/445ms14100 KiB
7Accepted4/445ms14152 KiB
8Accepted4/443ms14276 KiB
9Accepted2/2266ms21688 KiB
10Accepted2/2277ms21864 KiB
11Accepted2/2268ms21824 KiB
12Accepted2/2275ms21620 KiB
13Accepted2/2284ms21916 KiB
14Accepted3/3270ms21972 KiB
15Accepted2/2277ms21760 KiB
16Accepted2/2275ms21816 KiB
17Accepted2/2270ms22304 KiB
18Accepted2/2266ms22416 KiB
19Accepted3/3268ms22388 KiB
20Accepted2/2268ms22568 KiB
21Accepted2/2289ms22732 KiB
22Accepted3/3289ms22608 KiB
23Time limit exceeded0/2458ms46768 KiB
24Time limit exceeded0/2479ms43312 KiB
25Accepted2/2368ms54756 KiB
26Accepted2/2354ms56896 KiB
27Accepted2/2363ms55136 KiB
28Accepted2/2354ms56796 KiB
29Accepted2/2375ms56752 KiB
30Accepted2/2358ms57052 KiB
31Time limit exceeded0/2428ms58720 KiB
32Time limit exceeded0/2460ms57220 KiB