結果
問題 | No.1833 Subway Planning |
ユーザー | puzneko |
提出日時 | 2022-03-04 01:34:08 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,153 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 447,664 KB |
最終ジャッジ日時 | 2024-07-17 22:09:47 |
合計ジャッジ時間 | 41,325 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,864 KB |
testcase_01 | AC | 37 ms
53,944 KB |
testcase_02 | AC | 37 ms
53,016 KB |
testcase_03 | AC | 38 ms
52,696 KB |
testcase_04 | AC | 1,500 ms
348,088 KB |
testcase_05 | AC | 2,485 ms
388,256 KB |
testcase_06 | AC | 1,707 ms
348,328 KB |
testcase_07 | AC | 3,480 ms
349,316 KB |
testcase_08 | AC | 2,944 ms
344,368 KB |
testcase_09 | TLE | - |
testcase_10 | AC | 2,548 ms
357,312 KB |
testcase_11 | AC | 1,775 ms
428,968 KB |
testcase_12 | AC | 1,753 ms
438,700 KB |
testcase_13 | AC | 2,007 ms
360,908 KB |
testcase_14 | AC | 526 ms
213,864 KB |
testcase_15 | AC | 1,481 ms
260,472 KB |
testcase_16 | AC | 525 ms
213,960 KB |
testcase_17 | AC | 1,302 ms
210,112 KB |
testcase_18 | AC | 984 ms
209,048 KB |
testcase_19 | AC | 1,394 ms
179,156 KB |
testcase_20 | AC | 1,679 ms
164,092 KB |
testcase_21 | AC | 2,786 ms
334,812 KB |
testcase_22 | AC | 2,285 ms
292,864 KB |
testcase_23 | AC | 37 ms
53,868 KB |
testcase_24 | AC | 38 ms
54,208 KB |
testcase_25 | AC | 39 ms
53,652 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 = set() start = -1 for i in range(n-1): if c[i] > mid: mustin.add(a[i]) mustin.add(b[i]) start = i if start == -1: right = mid continue mustvisit = len(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) if now in mustin: visited += 1 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 now in mustin: 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) if now in mustin: visited += 1 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 now in mustin: 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))