結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-25 07:01:13 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,175 bytes |
| コンパイル時間 | 11,465 ms |
| コンパイル使用メモリ | 438,216 KB |
| 実行使用メモリ | 92,572 KB |
| 最終ジャッジ日時 | 2024-09-17 00:55:40 |
| 合計ジャッジ時間 | 16,448 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 42 |
ソースコード
import java.io.PrintWriter
import java.util.*
fun PrintWriter.solve() {
val n = nextInt()
val graph = Array(n) { mutableListOf<Int>() }
while (true) {
val a = nextInt() - 1
val b = nextInt() - 1
val c = next()
graph[a].add(b)
graph[b].add(a)
var num = 0
val stack = Stack<Pair<Int, Int>>()
stack.push(0 to -1)
while (stack.isNotEmpty()) {
val (v, p) = stack.pop()
num++
for (w in graph[v]) {
if (w != p) {
stack.push(w to v)
}
}
}
if (num == n) {
println(c)
return
}
}
}
fun main() {
val writer = PrintWriter(System.out, false)
writer.solve()
writer.flush()
}
// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()
fun next(): String {
while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
return st.nextToken()
}
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion