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
def main(): import sys input = sys.stdin.read().split() idx = 0 N, M = int(input[idx]), int(input[idx+1]) idx +=2 values = [] for _ in range(N): values.append(int(input[idx])) idx +=1 adj = [[] for _ in range(N)] for _ in range(M): u = int(input[idx])-1 # convert to 0-based v = int(input[idx+1])-1 idx +=2 if values[u] < values[v]: adj[u].append(v) elif values[v] < values[u]: adj[v].append(u) # Sort nodes by value, then by index to ensure deterministic order for same values nodes = sorted(range(N), key=lambda x: (values[x], x)) dp = [values[i] for i in range(N)] for u in nodes: for v in adj[u]: if dp[v] < dp[u] + values[v]: dp[v] = dp[u] + values[v] print(max(dp)) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.