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 is_dag(n, edges): adj = {i: [] for i in range(1, n+1)} for a, b in edges: adj[a].append(b) in_degree = [0] * (n + 1) for a in adj: for b in adj[a]: in_degree[b] += 1 q = deque() for i in range(1, n+1): if in_degree[i] == 0: q.append(i) cnt = 0 while q: u = q.popleft() cnt += 1 for v in adj[u]: in_degree[v] -= 1 if in_degree[v] == 0: q.append(v) return cnt == n 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): modified_edges = [] for j in range(m): if j == i: a, b = edges[j] modified_edges.append((b, a)) else: modified_edges.append(edges[j]) if is_dag(n, modified_edges): 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.