Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.026 s | 3 KBi |
#2 |
Correcto
|
0.028 s | 3 KBi |
#3 |
Correcto
|
0.032 s | 3 KBi |
#4 |
Correcto
|
0.033 s | 3 KBi |
#5 |
Correcto
|
0.028 s | 3 KBi |
#6 |
Correcto
|
0.025 s | 3 KBi |
#7 |
Correcto
|
0.025 s | 3 KBi |
#8 |
Correcto
|
0.028 s | 3 KBi |
#9 |
Correcto
|
0.027 s | 3 KBi |
#10 |
Correcto
|
0.025 s | 3 KBi |
#11 |
Correcto
|
0.029 s | 3 KBi |
#12 |
Correcto
|
0.025 s | 3 KBi |
#13 |
Correcto
|
0.024 s | 3 KBi |
#14 |
Correcto
|
0.025 s | 3 KBi |
#15 |
Correcto
|
0.033 s | 3 KBi |
#16 |
Correcto
|
0.024 s | 3 KBi |
#17 |
Correcto
|
0.028 s | 3 KBi |
#18 |
Correcto
|
0.033 s | 3 KBi |
#19 |
Correcto
|
0.026 s | 3 KBi |
#20 |
Correcto
|
0.025 s | 3 KBi |
#21 |
Correcto
|
0.023 s | 3 KBi |
#22 |
Correcto
|
0.029 s | 3 KBi |
#23 |
Correcto
|
0.03 s | 3 KBi |
#24 |
Correcto
|
0.028 s | 3 KBi |
#25 |
Correcto
|
0.026 s | 3 KBi |
#26 |
Correcto
|
0.038 s | 6 KBi |
#27 |
Correcto
|
0.276 s | 11 KBi |
#28 |
Correcto
|
0.04 s | 6 KBi |
#29 |
Correcto
|
0.284 s | 11 KBi |
#30 |
Correcto
|
0.04 s | 7 KBi |
#31 |
Correcto
|
0.08 s | 7 KBi |
#32 |
Correcto
|
0.308 s | 11 KBi |
#33 |
Correcto
|
0.086 s | 7 KBi |
#34 |
Correcto
|
0.096 s | 7 KBi |
#35 |
Correcto
|
0.209 s | 7 KBi |
from collections import defaultdict, deque def has_cycles(N, g): in_deg = defaultdict(int) for n in g: for nn in g[n]: in_deg[nn] += 1 q = deque([i for i in range(N) if in_deg[i] == 0]) res = 0 while q: node = q.popleft() res += 1 for nn in g[node]: in_deg[nn] -= 1 if in_deg[nn] == 0: q.append(nn) return res != N N, M = map(int, input().split(" ")) g = defaultdict(set) for _ in range(M): s, t = map(int, input().split(" ")) g[s].add(t) if has_cycles(N, g): print("Yes") else: print("No")