結果
| 問題 |
No.1400 すごろくで世界旅行
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:54:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,694 bytes |
| コンパイル時間 | 220 ms |
| コンパイル使用メモリ | 82,492 KB |
| 実行使用メモリ | 108,684 KB |
| 最終ジャッジ日時 | 2025-06-12 15:54:50 |
| 合計ジャッジ時間 | 3,204 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 1 |
ソースコード
import sys
from collections import deque
def main():
sys.setrecursionlimit(1 << 25)
V, D = map(int, sys.stdin.readline().split())
graph = []
has_self_loop = False
for i in range(V):
line = sys.stdin.readline().strip()
adj = [int(c) for c in line]
graph.append(adj)
if adj[i] == 1:
has_self_loop = True
# Check if the graph is connected
visited = [False] * V
q = deque()
q.append(0)
visited[0] = True
while q:
u = q.popleft()
for v in range(V):
if graph[u][v] == 1 and not visited[v]:
visited[v] = True
q.append(v)
if not all(visited):
print("No")
return
# Check bipartiteness
color = [-1] * V
is_bipartite = True
for start in range(V):
if color[start] == -1:
color[start] = 0
q = deque()
q.append(start)
while q:
u = q.popleft()
for v in range(V):
if graph[u][v] == 1:
if color[v] == -1:
color[v] = color[u] ^ 1
q.append(v)
elif color[v] == color[u]:
is_bipartite = False
break
if not is_bipartite:
break
if not is_bipartite:
break
if not is_bipartite:
print("Yes")
return
else:
# Check if any node has a self-loop
if has_self_loop:
print("Yes")
else:
print("No")
if __name__ == '__main__':
main()
gew1fw