結果
問題 |
No.1424 Ultrapalindrome
|
ユーザー |
![]() |
提出日時 | 2021-03-12 22:10:06 |
言語 | Kotlin (2.1.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,125 bytes |
コンパイル時間 | 13,228 ms |
コンパイル使用メモリ | 444,560 KB |
実行使用メモリ | 115,088 KB |
最終ジャッジ日時 | 2024-10-14 12:39:41 |
合計ジャッジ時間 | 34,055 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 WA * 4 RE * 2 |
コンパイルメッセージ
Main.kt:33:10: warning: parameter 'args' is never used fun main(args : Array<String>) { ^
ソースコード
data class Node ( val id: Int, var col: Int, val ngh: ArrayList<Node> = ArrayList<Node>() ){ fun colorize(c: Int): Boolean { // println("$id -> $c") if(col > 0) return col == c col = c for(x in ngh){ x.colorize(3 - c) } return true } } class Graph(N: Int) { val nodes = ArrayList<Node>() init { for (i in 0 until N) { nodes.add(Node(i, 0)) } } fun join(a:Int, b:Int){ nodes[a].ngh.add(nodes[b]) nodes[b].ngh.add(nodes[a]) } } fun main(args : Array<String>) { val N = readLine()!!.toInt() val g = Graph(N) val seen = HashSet<Int>() val leaves = HashSet<Int>() for(t in 1 until N) { val (a, b) = readLine()!!.split(" ").map { it.toInt() - 1} g.join(a, b) if(a in seen)leaves.remove(a) else leaves.add(a) if(b in seen)leaves.remove(b) else leaves.add(b) seen.add(a) seen.add(b) } var ok = true for(x in leaves) { ok = ok && g.nodes[x].colorize(1) } println(if(ok)"Yes" else "No") }