結果
問題 | No.1833 Subway Planning |
ユーザー | yudedako |
提出日時 | 2022-02-22 11:59:13 |
言語 | Scala(Beta) (3.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,896 bytes |
コンパイル時間 | 14,835 ms |
コンパイル使用メモリ | 259,160 KB |
実行使用メモリ | 147,024 KB |
最終ジャッジ日時 | 2023-09-13 02:30:51 |
合計ジャッジ時間 | 76,519 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,016 ms
63,204 KB |
testcase_01 | AC | 1,018 ms
62,996 KB |
testcase_02 | AC | 1,020 ms
62,992 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1,972 ms
138,904 KB |
testcase_05 | AC | 1,928 ms
137,108 KB |
testcase_06 | AC | 2,794 ms
139,676 KB |
testcase_07 | WA | - |
testcase_08 | AC | 2,989 ms
140,016 KB |
testcase_09 | AC | 2,110 ms
137,000 KB |
testcase_10 | AC | 2,916 ms
147,024 KB |
testcase_11 | AC | 2,667 ms
142,452 KB |
testcase_12 | AC | 2,248 ms
139,696 KB |
testcase_13 | AC | 2,994 ms
143,504 KB |
testcase_14 | AC | 2,653 ms
138,000 KB |
testcase_15 | AC | 2,064 ms
138,420 KB |
testcase_16 | AC | 2,932 ms
139,360 KB |
testcase_17 | AC | 2,959 ms
139,696 KB |
testcase_18 | AC | 2,842 ms
137,828 KB |
testcase_19 | AC | 2,204 ms
138,584 KB |
testcase_20 | AC | 2,084 ms
126,900 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 1,057 ms
63,560 KB |
testcase_24 | AC | 1,030 ms
63,636 KB |
testcase_25 | AC | 1,041 ms
62,948 KB |
ソースコード
import scala.collection.mutable.* import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* import scala.reflect.{ClassTag, classTag} import scala.util.* import scala.annotation.tailrec import scala.collection.mutable @main def main = val n = readLine.toInt val edges = Array.fill(n - 1){ val Array(a, b, c) = readLine.split(' ').map(_.toInt) (a - 1, b - 1, c) } val graph = Array.fill(n){ArrayBuffer[(Int, Int)]()} for (a, b, c) <- edges do graph(a).addOne((b, c)) graph(b).addOne((a, c)) val sortedEdge = edges.sortBy(-_._3) val root = sortedEdge.head._1 val depth = Array.fill(n){-1}.tap(_(root) = 0) val parent = Array.fill(n){-1} val cost = Array.fill(n){-1} val stack = mutable.Stack[Int](root) while stack.nonEmpty do val top = stack.pop() for (next, c) <- graph(top) do if depth(next) == -1 then depth(next) = depth(top) + 1 parent(next) = top cost(next) = c stack.push(next) val degree = Array.fill(n){0} var canReduceAll = true var currentMin = Int.MaxValue val onPath = Array.fill(n){false}.tap(_(root) = true) var result = sortedEdge(0)._3 for i <- sortedEdge.indices do if canReduceAll then val (a, b, _) = sortedEdge(i) val nextCost = if sortedEdge.indices.contains(i + 1) then sortedEdge(i + 1)._3 else 0 val start = if depth(a) < depth(b) then b else a if !onPath(start) then var current = start while !onPath(current) do currentMin = min(currentMin, cost(current)) onPath(current) = true current = parent(current) degree(current) += 1 if (current != root && degree(current) > 1) || (current == root && degree(current) > 2) then canReduceAll = false else result = min(result, max(nextCost, sortedEdge.head._3 - currentMin)) println(result)