結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-25 07:11:11 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 442 ms / 2,000 ms |
| コード長 | 1,259 bytes |
| コンパイル時間 | 12,903 ms |
| コンパイル使用メモリ | 440,552 KB |
| 実行使用メモリ | 59,496 KB |
| 最終ジャッジ日時 | 2024-09-17 00:56:57 |
| 合計ジャッジ時間 | 28,953 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
import java.io.PrintWriter
import java.util.*
fun PrintWriter.solve() {
val n = nextInt()
val graph = Array(n) { mutableListOf<Int>() }
for (i in 0 until n * (n - 1) / 2) {
val a = nextInt() - 1
val b = nextInt() - 1
val c = next()
graph[a].add(b)
graph[b].add(a)
val visited = BooleanArray(n) { false }
val stack = Stack<Int>()
stack.push(0)
visited[0] = true
while (stack.isNotEmpty()) {
val v = stack.pop()
for (w in graph[v]) {
if (!visited[w]) {
stack.push(w)
visited[w] = true
}
}
}
if (visited.all { it }) {
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