Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Incorrecto
|
0.028 s | 3 KBi |
#2 |
Correcto
|
0.025 s | 3 KBi |
#3 |
Correcto
|
0.022 s | 3 KBi |
#4 |
Incorrecto
|
0.028 s | 3 KBi |
#5 |
Correcto
|
0.024 s | 3 KBi |
#6 |
Incorrecto
|
0.025 s | 3 KBi |
#7 |
Incorrecto
|
0.024 s | 3 KBi |
#8 |
Incorrecto
|
0.033 s | 3 KBi |
#9 |
Incorrecto
|
0.029 s | 3 KBi |
#10 |
Incorrecto
|
0.026 s | 3 KBi |
#11 |
Correcto
|
0.026 s | 3 KBi |
#12 |
Correcto
|
0.024 s | 3 KBi |
#13 |
Incorrecto
|
0.032 s | 3 KBi |
#14 |
Correcto
|
0.025 s | 3 KBi |
#15 |
Incorrecto
|
0.025 s | 3 KBi |
#16 |
Incorrecto
|
0.022 s | 3 KBi |
#17 |
Incorrecto
|
0.027 s | 3 KBi |
#18 |
Correcto
|
0.025 s | 3 KBi |
#19 |
Correcto
|
0.029 s | 3 KBi |
#20 |
Correcto
|
0.022 s | 3 KBi |
#21 |
Correcto
|
0.027 s | 3 KBi |
#22 |
Correcto
|
0.026 s | 3 KBi |
#23 |
Correcto
|
0.032 s | 3 KBi |
#24 |
Correcto
|
0.036 s | 3 KBi |
#25 |
Correcto
|
0.037 s | 3 KBi |
#26 |
Correcto
|
0.042 s | 5 KBi |
#27 |
Correcto
|
0.313 s | 13 KBi |
#28 |
Correcto
|
0.033 s | 5 KBi |
#29 |
Correcto
|
0.213 s | 13 KBi |
#30 |
Correcto
|
0.038 s | 5 KBi |
#31 |
Correcto
|
0.066 s | 7 KBi |
#32 |
Incorrecto
|
0.198 s | 13 KBi |
#33 |
Incorrecto
|
0.101 s | 7 KBi |
#34 |
Correcto
|
0.07 s | 8 KBi |
#35 |
Incorrecto
|
0.265 s | 13 KBi |
from collections import defaultdict def has_cycles(g, N): s = set() for i in range(N): if i not in s: if dfs(g, i, s): return True return False def dfs(g, node, s): s.add(node) for nn in g[node]: if nn in s: return True if dfs(g, nn, s): return True return False N, M = map(int, input().split(" ")) g = defaultdict(list) for _ in range(M): s, t = input().split(" ") g[s].append(t) g[t].append(s) if has_cycles(g, N): print("Yes") else: print("No")