結果
問題 | No.274 The Wall |
ユーザー |
|
提出日時 | 2021-03-01 04:38:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 802 ms / 2,000 ms |
コード長 | 1,230 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-10-03 00:44:56 |
合計ジャッジ時間 | 8,417 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
import sysreadline = sys.stdin.readlinedef crossing(M, b0, b1):l0, r0 = b0l1, r1 = b1t0 = l1 <= r0 and l0 <= r1l0, r0 = M - 1 - r0, M - 1 - l0t1 = l1 <= r0 and l0 <= r1if t0 and t1:return "NG"if t0 or t1:return Truereturn Falsedef dfs(x, G, color, now):color[x] = nowfor y in G[x]:if color[y] >= 0:if color[y] == now:return Falsecontinueif not dfs(y, G, color, 1 - now):return Falsereturn Truedef main():N, M = map(int, readline().split())blocks = [tuple(map(int, readline().split())) for _ in range(N)]G = [[] for _ in range(N)]for i in range(N):for j in range(i + 1, N):t = crossing(M, blocks[i], blocks[j])if t == "NG":print("NO")returnif t:G[i].append(j)G[j].append(i)is_bipartite = Truecolor = [-1] * Nfor x in range(N):if color[x] >= 0:continueif not dfs(x, G, color, 0):is_bipartite = Falseprint("YES" if is_bipartite else "NO")if __name__ == "__main__":main()