94962024-02-22 12:01:22Leventusz09Túra (75 pont)python3Runtime error 0/75465ms66148 KiB
def dfs(node, parent):
    global ans, beauty, visited
    visited[node] = True
    for child in graph[node]:
        if child != parent:
            if visited[child]:
                ans = 1
                return
            beauty += values[child]
            dfs(child, node)
            if ans:
                return
            beauty -= values[child]


t = int(input())
for _ in range(t):
    n = int(input())
    values = list(map(int, input().split()))
    graph = {i+1: [] for i in range(n)}
    for _ in range(n-1):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    visited = [False] * (n+1)
    ans = 0
    for i in range(1, n+1):
        if not visited[i]:
            beauty = values[i-1]
            dfs(i, 0)
            if ans:
                break

    if ans:
        print("NEM")
        bad_tour = []
        visited = [False] * (n+1)
        for i in range(1, n+1):
            if visited[i]:
                break
            visited[i] = True
            if values[i-1] == -1:
                bad_tour.append(i)
            for child in graph[i]:
                visited[child] = True
                if values[child-1] == -1:
                    bad_tour.append(child)
            if sum(values[i-1] for i in bad_tour) < 0:
                break
        print(len(bad_tour))
        print(*bad_tour)
    else:
        print("IGEN")
SubtaskSumTestVerdictTimeMemory
base0/75
1Runtime error0/019ms11640 KiB
2Runtime error0/018ms11844 KiB
3Runtime error0/618ms12076 KiB
4Runtime error0/321ms12828 KiB
5Runtime error0/321ms12988 KiB
6Runtime error0/421ms13016 KiB
7Runtime error0/421ms13364 KiB
8Runtime error0/420ms13124 KiB
9Runtime error0/254ms17504 KiB
10Runtime error0/256ms18048 KiB
11Runtime error0/254ms17832 KiB
12Runtime error0/252ms18260 KiB
13Runtime error0/256ms18320 KiB
14Runtime error0/356ms18276 KiB
15Runtime error0/254ms18500 KiB
16Runtime error0/252ms18580 KiB
17Runtime error0/252ms18612 KiB
18Runtime error0/254ms18592 KiB
19Runtime error0/356ms18596 KiB
20Runtime error0/252ms18916 KiB
21Runtime error0/250ms18768 KiB
22Runtime error0/352ms18940 KiB
23Time limit exceeded0/2465ms33068 KiB
24Time limit exceeded0/2456ms66148 KiB
25Runtime error0/2230ms41076 KiB
26Runtime error0/2206ms40172 KiB
27Runtime error0/2209ms40676 KiB
28Runtime error0/2215ms40488 KiB
29Runtime error0/2194ms40412 KiB
30Runtime error0/2219ms40176 KiB
31Runtime error0/2231ms40808 KiB
32Runtime error0/2228ms40156 KiB