結果
| 問題 |
No.274 The Wall
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-20 23:31:51 |
| 言語 | Python2 (2.7.18) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,063 bytes |
| コンパイル時間 | 347 ms |
| コンパイル使用メモリ | 7,076 KB |
| 実行使用メモリ | 34,560 KB |
| 最終ジャッジ日時 | 2024-11-22 16:56:54 |
| 合計ジャッジ時間 | 13,769 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 17 WA * 5 |
ソースコード
N, M = map(int, raw_input().split())
blocks = [map(int, raw_input().split()) for _ in xrange(N)]
rinsetsu = [[] for _ in xrange(N)]
for i in xrange(N):
for j in xrange(i+1, N):
L1, R1 = blocks[i]
L2, R2 = blocks[j]
L3, R3 = R2-N-1, L2-N-1
b1 = L1 <= L2 <= R1 or L1 <= R2 <= R1
b2 = L1 <= L3 <= R1 or L1 <= R3 <= R1
if b1 and b2:
print 'NO'
exit()
elif b1 or b2:
rinsetsu[i].append(j)
rinsetsu[j].append(i)
def dfs(start, color):
color[start] = 0
stack = [start]
while len(stack) > 0:
node = stack.pop()
next_color = (color[node]+1)%2
for next_node in rinsetsu[node]:
if color[next_node] == -1:
color[next_node] = next_color
elif color[next_node] != next_color:
return False
return color
color = [-1 for _ in xrange(N)]
for i in xrange(N):
if color[i] == -1:
color = dfs(i, color)
if not color:
print 'NO'
exit()
print 'YES'