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
pythonfrom collections import deque # Read input n, m = map(int, input().split()) values = [0] # 1-based indexing for _ in range(n): values.append(int(input())) # Build adjacency list adj = [[] for _ in range(n + 1)] for _ in range(m): u, v = map(int, input().split()) adj[u].append(v) # BFS from node 1 to find all reachable nodes visited = set() q = deque([1]) visited.add(1) total = 0 while q: u = q.popleft() total += values[u] for v in adj[u]: if v not in visited: visited.add(v) q.append(v) print(total)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.