結果
問題 |
No.1400 すごろくで世界旅行
|
ユーザー |
![]() |
提出日時 | 2025-04-16 16:23:51 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,526 bytes |
コンパイル時間 | 560 ms |
コンパイル使用メモリ | 82,500 KB |
実行使用メモリ | 80,472 KB |
最終ジャッジ日時 | 2025-04-16 16:24:37 |
合計ジャッジ時間 | 2,826 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 1 |
ソースコード
import sys from collections import deque def main(): V, D = map(int, sys.stdin.readline().split()) E = [sys.stdin.readline().strip() for _ in range(V)] # Check if the graph is connected using BFS visited = [False] * V queue = deque([0]) visited[0] = True while queue: u = queue.popleft() for v in range(V): if E[u][v] == '1' and not visited[v]: visited[v] = True queue.append(v) if not all(visited): print("No") return # Check if all vertices have self-loops all_self_loop = all(E[i][i] == '1' for i in range(V)) if all_self_loop: print("Yes") return # Check if the graph is bipartite using BFS color = [-1] * V is_bipartite = True for i in range(V): if color[i] == -1: color[i] = 0 queue = deque([i]) while queue: u = queue.popleft() for v in range(V): if E[u][v] == '1': if color[v] == -1: color[v] = color[u] ^ 1 queue.append(v) elif color[v] == color[u]: is_bipartite = False break if not is_bipartite: break if not is_bipartite: break if is_bipartite: print("No") else: print("Yes") if __name__ == "__main__": main()