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 defaultdict def main(): N, M = map(int, sys.stdin.readline().split()) edges = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] adj = defaultdict(set) adj_in = defaultdict(set) for a, b in edges: adj[a].add(b) adj_in[b].add(a) # Check for existing triangles for u in adj: for v in adj[u]: for w in adj[v]: if u in adj[w]: print("YES") return # Check all possible pairs to add an edge for u in range(1, N+1): for v in range(1, N+1): if u == v: continue if v in adj[u] or u in adj[v]: continue # Check adding u->v if not adj[v].isdisjoint(adj_in[u]): print("YES") return # Check adding v->u if not adj[u].isdisjoint(adj_in[v]): 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.