4810 | 2023-03-31 12:45:50 | Leventusz19 | Túra (75 pont) | csharp | Compilation error |
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")
exit status 1
Compilation failed: 1 error(s), 0 warnings
main.cs(1,0): error CS1525: Unexpected symbol `def'
Exited with error status 1