結果
問題 | No.1400 すごろくで世界旅行 |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:34:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,648 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 108,800 KB |
最終ジャッジ日時 | 2025-03-31 17:35:17 |
合計ジャッジ時間 | 3,806 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 WA * 1 |
ソースコード
import sysfrom collections import dequedef main():sys.setrecursionlimit(1 << 25)V, D = map(int, sys.stdin.readline().split())E = []for _ in range(V):line = sys.stdin.readline().strip()row = [int(c) for c in line]E.append(row)# Step 1: Check all nodes have at least one outgoing edgefor i in range(V):if sum(E[i]) == 0:print("No")return# Step 2: Check if the graph is connected (BFS)visited = [False]*Vq = deque()q.append(0)visited[0] = Truewhile q:u = q.popleft()for v in range(V):if E[u][v] and not visited[v]:visited[v] = Trueq.append(v)if not all(visited):print("No")return# Step 3: Check if the graph is bipartite (BFS)color = [-1]*Vis_bipartite = Truefor start in range(V):if color[start] == -1:q = deque()q.append(start)color[start] = 0while q:u = q.popleft()for v in range(V):if E[u][v]:if color[v] == -1:color[v] = color[u] ^ 1q.append(v)elif color[v] == color[u]:is_bipartite = Falsebreakif not is_bipartite:breakif not is_bipartite:breakif is_bipartite:print("No")else:print("Yes")if __name__ == "__main__":main()