結果
問題 | No.1424 Ultrapalindrome |
ユーザー | 箱星 |
提出日時 | 2020-09-18 01:17:41 |
言語 | Kotlin (1.9.23) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,599 bytes |
コンパイル時間 | 14,697 ms |
コンパイル使用メモリ | 462,816 KB |
実行使用メモリ | 139,584 KB |
最終ジャッジ日時 | 2024-05-03 09:04:31 |
合計ジャッジ時間 | 39,219 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 285 ms
60,056 KB |
testcase_01 | AC | 302 ms
60,204 KB |
testcase_02 | AC | 291 ms
60,092 KB |
testcase_03 | AC | 290 ms
60,160 KB |
testcase_04 | AC | 290 ms
60,068 KB |
testcase_05 | AC | 297 ms
60,008 KB |
testcase_06 | AC | 302 ms
60,064 KB |
testcase_07 | AC | 287 ms
60,160 KB |
testcase_08 | WA | - |
testcase_09 | AC | 1,135 ms
115,096 KB |
testcase_10 | AC | 1,096 ms
117,028 KB |
testcase_11 | AC | 937 ms
108,540 KB |
testcase_12 | AC | 1,079 ms
114,936 KB |
testcase_13 | AC | 612 ms
83,232 KB |
testcase_14 | AC | 1,005 ms
107,036 KB |
testcase_15 | AC | 314 ms
60,372 KB |
testcase_16 | AC | 920 ms
106,228 KB |
testcase_17 | AC | 1,011 ms
108,652 KB |
testcase_18 | AC | 831 ms
104,640 KB |
testcase_19 | AC | 845 ms
105,776 KB |
testcase_20 | AC | 545 ms
76,852 KB |
testcase_21 | AC | 834 ms
106,704 KB |
testcase_22 | AC | 710 ms
91,772 KB |
testcase_23 | AC | 493 ms
71,416 KB |
testcase_24 | AC | 561 ms
79,228 KB |
testcase_25 | AC | 537 ms
79,248 KB |
testcase_26 | AC | 1,008 ms
106,908 KB |
testcase_27 | WA | - |
testcase_28 | AC | 991 ms
136,632 KB |
testcase_29 | AC | 978 ms
136,800 KB |
testcase_30 | AC | 1,137 ms
136,060 KB |
testcase_31 | WA | - |
コンパイルメッセージ
Main.kt:28:25: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int val max = dist.max()!! ^ Main.kt:40:26: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int val diam = dist.max()!! ^ Main.kt:58:14: warning: variable 'min' is never used val (v1, min) = leaves.minBy { it.second }!! ^ Main.kt:58:47: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Pair<Int, Int> val (v1, min) = leaves.minBy { it.second }!! ^ Main.kt:75:43: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int val l = leaves.map { it.second }.min()!! ^
ソースコード
import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.io.PrintWriter import java.util.* fun PrintWriter.solve(sc: FastScanner) { val n = sc.nextInt() val adj = Array(n) { mutableSetOf<Int>() } for (i in 0 until n - 1) { val v1 = sc.nextInt() - 1 val v2 = sc.nextInt() - 1 adj[v1].add(v2) adj[v2].add(v1) } val que: Queue<Triple<Int, Int, Int>> = ArrayDeque() que.add(Triple(0, -1, 0)) val dist = Array(n) { 0 } while (que.count() > 0) { val (v, p, d) = que.poll() dist[v] = d for (w in adj[v]) { if (w != p) { que.add(Triple(w, v, d + 1)) } } } val max = dist.max()!! val v0 = (0 until n).first { dist[it] == max } que.add(Triple(v0, -1, 0)) while (que.count() > 0) { val (v, p, d) = que.poll() dist[v] = d for (w in adj[v]) { if (w != p) { que.add(Triple(w, v, d + 1)) } } } val diam = dist.max()!! que.add(Triple(0, -1, 0)) val leaves = mutableListOf<Pair<Int, Int>>() while (que.count() > 0) { val (v, p, d) = que.poll() dist[v] = d var isleaf = true for (w in adj[v]) { if (w != p) { isleaf = false que.add(Triple(w, v, d + 1)) } } if (isleaf) { leaves.add(v to d) } } val (v1, min) = leaves.minBy { it.second }!! que.add(Triple(v1, -1, 0)) leaves.clear() while (que.count() > 0) { val (v, p, d) = que.poll() dist[v] = d var isleaf = true for (w in adj[v]) { if (w != p) { isleaf = false que.add(Triple(w, v, d + 1)) } } if (isleaf) { leaves.add(v to d) } } val l = leaves.map { it.second }.min()!! println(if (diam == l) "Yes" else "No") } fun main() { val writer = PrintWriter(System.out, false) writer.solve(FastScanner(System.`in`)) writer.flush() } class FastScanner(s: InputStream) { private var st = StringTokenizer("") private val br = BufferedReader(InputStreamReader(s)) 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() fun ready() = br.ready() }