92092024-02-18 16:24:33FarkasZénóTúra (75 pont)python3Time limit exceeded 67/75465ms101552 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)
	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/020ms11856 KiB
2Accepted0/021ms12456 KiB
3Accepted6/619ms12300 KiB
4Accepted3/345ms13812 KiB
5Accepted3/345ms13892 KiB
6Accepted4/446ms14396 KiB
7Accepted4/443ms14520 KiB
8Accepted4/445ms15016 KiB
9Accepted2/2264ms22220 KiB
10Accepted2/2277ms23124 KiB
11Accepted2/2270ms23740 KiB
12Accepted2/2275ms24332 KiB
13Accepted2/2279ms25300 KiB
14Accepted3/3266ms26952 KiB
15Accepted2/2275ms27656 KiB
16Accepted2/2284ms28396 KiB
17Accepted2/2268ms29844 KiB
18Accepted2/2268ms31332 KiB
19Accepted3/3264ms31728 KiB
20Accepted2/2266ms32568 KiB
21Accepted2/2289ms33872 KiB
22Accepted3/3284ms35064 KiB
23Time limit exceeded0/2465ms59460 KiB
24Time limit exceeded0/2423ms101552 KiB
25Accepted2/2333ms70196 KiB
26Accepted2/2323ms73152 KiB
27Accepted2/2328ms72048 KiB
28Accepted2/2326ms75208 KiB
29Accepted2/2365ms76584 KiB
30Accepted2/2363ms77660 KiB
31Time limit exceeded0/2432ms80872 KiB
32Time limit exceeded0/2425ms80320 KiB