結果
問題 | No.1833 Subway Planning |
ユーザー | puzneko |
提出日時 | 2022-03-04 01:38:29 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,101 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,040 KB |
実行使用メモリ | 382,284 KB |
最終ジャッジ日時 | 2024-07-17 22:14:11 |
合計ジャッジ時間 | 40,284 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,052 KB |
testcase_01 | AC | 39 ms
52,488 KB |
testcase_02 | AC | 40 ms
52,608 KB |
testcase_03 | AC | 40 ms
52,272 KB |
testcase_04 | AC | 1,381 ms
295,672 KB |
testcase_05 | AC | 2,214 ms
346,388 KB |
testcase_06 | AC | 1,735 ms
376,960 KB |
testcase_07 | AC | 3,802 ms
358,628 KB |
testcase_08 | AC | 3,027 ms
346,836 KB |
testcase_09 | TLE | - |
testcase_10 | AC | 2,762 ms
360,576 KB |
testcase_11 | AC | 1,650 ms
382,284 KB |
testcase_12 | AC | 1,359 ms
339,188 KB |
testcase_13 | AC | 2,131 ms
371,672 KB |
testcase_14 | AC | 570 ms
207,452 KB |
testcase_15 | AC | 1,373 ms
196,008 KB |
testcase_16 | AC | 572 ms
229,708 KB |
testcase_17 | AC | 1,423 ms
199,028 KB |
testcase_18 | AC | 1,139 ms
205,460 KB |
testcase_19 | AC | 1,482 ms
200,900 KB |
testcase_20 | AC | 1,773 ms
182,252 KB |
testcase_21 | AC | 2,635 ms
295,556 KB |
testcase_22 | AC | 2,288 ms
292,488 KB |
testcase_23 | AC | 41 ms
52,480 KB |
testcase_24 | AC | 41 ms
52,480 KB |
testcase_25 | AC | 41 ms
52,224 KB |
ソースコード
from sys import stdin n, *indata = map(int, stdin.read().split()) offset = 0 a = [] b = [] c = [] g = [[] for i in range(n+1)] for i in range(n-1): s, t, d = indata[offset + 3*i]-1,indata[offset + 3*i+1]-1,indata[offset + 3*i+2] a.append(s) b.append(t) c.append(d) g[s].append((t,d)) g[t].append((s,d)) left = -1 right = max(c) + 2 while right - left >= 2: mid = (right + left) // 2 mustin = [0 for i in range(n)] start = -1 for i in range(n-1): if c[i] > mid: mustin[a[i]] = 1 mustin[b[i]] = 1 start = i if start == -1: right = mid continue mustvisit = sum(mustin) visited = 0 used = [c[start]] check = [False for i in range(n)] check[a[start]] = True check[b[start]] = True que = [(a[start],0,-1)] while que: now, inout, come = que.pop() if inout == 0: check[now] = True if come != -1: used.append(come) visited += mustin[now] if visited == mustvisit: break que.append((now,1,come)) for i, cost in g[now]: if not check[i]: que.append((i,0,cost)) else: if mustin[now]: break else: used.pop() que = [(b[start],0,-1)] while que: now, inout, come = que.pop() if inout == 0: check[now] = True if come != -1: used.append(come) visited += mustin[now] if visited == mustvisit: break que.append((now,1,come)) for i, cost in g[now]: if not check[i]: que.append((i,0,cost)) else: if mustin[now]: break else: used.pop() if visited != mustvisit: left = mid else: val = max(used) - min(used) if val <= mid: right = mid else: left = mid print("{}".format(right))