93462024-02-20 17:30:19FarkasZénóTúra (75 pont)pypy3Runtime error 71/75328ms169012 KiB
from sys import stdin

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 = [set() for _ in range(N+1)]
	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/052ms81840 KiB
2Accepted0/054ms85552 KiB
3Accepted6/646ms83504 KiB
4Accepted3/393ms97244 KiB
5Accepted3/387ms97388 KiB
6Accepted4/483ms97808 KiB
7Accepted4/483ms97840 KiB
8Accepted4/4108ms98320 KiB
9Accepted2/2238ms154348 KiB
10Accepted2/2233ms156816 KiB
11Accepted2/2254ms156132 KiB
12Accepted2/2246ms155792 KiB
13Accepted2/2250ms157608 KiB
14Accepted3/3246ms156728 KiB
15Accepted2/2252ms156524 KiB
16Accepted2/2263ms154948 KiB
17Accepted2/2254ms158448 KiB
18Accepted2/2234ms158744 KiB
19Accepted3/3231ms159904 KiB
20Accepted2/2229ms160924 KiB
21Accepted2/2237ms162652 KiB
22Accepted3/3261ms159996 KiB
23Accepted2/2225ms165780 KiB
24Accepted2/2222ms162884 KiB
25Accepted2/2266ms163944 KiB
26Runtime error0/2244ms169012 KiB
27Accepted2/2231ms163488 KiB
28Accepted2/2224ms168132 KiB
29Accepted2/2250ms166256 KiB
30Runtime error0/2230ms168160 KiB
31Accepted2/2328ms167948 KiB
32Accepted2/2301ms164796 KiB