結果

問題 No.1244 Black Segment
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-29 21:01:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 622 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 86,380 KB
実行使用メモリ 102,116 KB
最終ジャッジ日時 2023-09-08 06:13:10
合計ジャッジ時間 10,364 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,296 KB
testcase_01 AC 95 ms
71,324 KB
testcase_02 AC 96 ms
71,208 KB
testcase_03 AC 73 ms
71,020 KB
testcase_04 AC 74 ms
71,016 KB
testcase_05 AC 94 ms
71,556 KB
testcase_06 AC 94 ms
71,268 KB
testcase_07 AC 95 ms
71,220 KB
testcase_08 AC 93 ms
71,604 KB
testcase_09 AC 93 ms
71,612 KB
testcase_10 AC 92 ms
71,244 KB
testcase_11 AC 93 ms
71,600 KB
testcase_12 AC 73 ms
70,968 KB
testcase_13 AC 158 ms
78,376 KB
testcase_14 AC 220 ms
89,292 KB
testcase_15 AC 141 ms
78,496 KB
testcase_16 AC 212 ms
87,816 KB
testcase_17 AC 131 ms
77,956 KB
testcase_18 AC 142 ms
81,908 KB
testcase_19 AC 165 ms
86,156 KB
testcase_20 AC 251 ms
95,288 KB
testcase_21 AC 230 ms
92,196 KB
testcase_22 AC 260 ms
95,440 KB
testcase_23 AC 273 ms
97,184 KB
testcase_24 AC 265 ms
97,196 KB
testcase_25 AC 247 ms
95,472 KB
testcase_26 AC 259 ms
97,096 KB
testcase_27 AC 267 ms
102,116 KB
testcase_28 AC 261 ms
97,904 KB
testcase_29 AC 261 ms
98,388 KB
testcase_30 AC 250 ms
96,420 KB
testcase_31 AC 270 ms
98,604 KB
testcase_32 AC 273 ms
100,752 KB
testcase_33 AC 273 ms
98,352 KB
testcase_34 AC 178 ms
88,220 KB
testcase_35 AC 206 ms
88,976 KB
testcase_36 AC 242 ms
95,924 KB
testcase_37 AC 271 ms
99,480 KB
testcase_38 AC 176 ms
88,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,a,b=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
g=[[] for _ in range(n+3)]
a,b=a-1,b
for l,r in lr:
  l,r=l-1,r
  if r<=a or b<=l:
    continue
  if l<=a and b<=r:
    print(1)
    exit()
  elif a<l<=r<b:
    g[l].append(r)
    g[r].append(l)
  elif l<=a<=r:
    g[n+1].append(r)
    g[r].append(n+1)
  else:
    g[n+2].append(l)
    g[l].append(n+2)
#print(g)
from collections import deque
seen=[-1]*(n+3)
todo=deque([n+1])
seen[n+1]=0
while todo:
  v=todo.popleft()
  for nv in g[v]:
    if seen[nv]==-1:
      seen[nv]=seen[v]+1
      todo.append(nv)
print(seen[n+2])
#print(seen)
0