93452024-02-20 17:29:03FarkasZénóTúra (75 pont)python3Time limit exceeded 69/75465ms77772 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
base69/75
1Accepted0/017ms11296 KiB
2Accepted0/018ms11928 KiB
3Accepted6/617ms12256 KiB
4Accepted3/341ms13720 KiB
5Accepted3/341ms13980 KiB
6Accepted4/441ms14224 KiB
7Accepted4/441ms14308 KiB
8Accepted4/439ms14708 KiB
9Accepted2/2239ms25472 KiB
10Accepted2/2250ms26140 KiB
11Accepted2/2250ms26232 KiB
12Accepted2/2246ms26480 KiB
13Accepted2/2246ms26252 KiB
14Accepted3/3250ms26328 KiB
15Accepted2/2250ms26652 KiB
16Accepted2/2250ms26476 KiB
17Accepted2/2256ms26764 KiB
18Accepted2/2247ms27116 KiB
19Accepted3/3248ms26828 KiB
20Accepted2/2246ms27184 KiB
21Accepted2/2266ms27360 KiB
22Accepted3/3261ms27384 KiB
23Time limit exceeded0/2465ms43524 KiB
24Accepted2/2389ms77772 KiB
25Accepted2/2386ms69284 KiB
26Accepted2/2382ms73960 KiB
27Accepted2/2326ms68960 KiB
28Accepted2/2375ms73648 KiB
29Accepted2/2389ms70696 KiB
30Accepted2/2389ms74116 KiB
31Time limit exceeded0/2437ms75536 KiB
32Time limit exceeded0/2446ms70748 KiB