This issue is the same configuration issue as G: DAG Trio (Hard), with only the…
- User
This issue is the same configuration issue as G: DAG Trio (Hard), with only the constraints being different. input
Assistant
pythonimport sys from collections import deque def main(): N, M = map(int, sys.stdin.readline().split()) edges = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] for i in range(M): a, b = edges[i] new_edges = edges[:i] + edges[i+1:] + [(b, a)] adj = [[] for _ in range(N+1)] in_deg = [0]*(N+1) for u, v in new_edges: adj[u].append(v) in_deg[v] += 1 q = deque() cnt = 0 for node in range(1, N+1): if in_deg[node] == 0: q.append(node) while q: u = q.popleft() cnt += 1 for v in adj[u]: in_deg[v] -= 1 if in_deg[v] == 0: q.append(v) if cnt == N: print("YES") return print("NO") 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.