Example Input 6 6 3 1 9 4 3 6 1 2 1 4 2 6 5 4 6 5 3 2 Output 17
- User
Example Input
6 6 3 1 9 4 3 6 1 2 1 4 2 6 5 4 6 5 3 2
Output
17
Assistant
n, m = map(int, input().split()) values = [0] for _ in range(n): values.append(int(input())) adj = [[] for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) adj[u].append(v) adj[v].append(u) max_sum = 0 def dfs(node, visited, current_sum): global max_sum max_sum = max(max_sum, current_sum) for neighbor in adj[node]: if neighbor not in visited: dfs(neighbor, visited | {neighbor}, current_sum + values[neighbor]) for node in range(1, n + 1): dfs(node, {node}, values[node]) print(max_sum)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.