結果

問題 No.1424 Ultrapalindrome
ユーザー leetcoincollectorleetcoincollector
提出日時 2021-03-12 22:10:06
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,125 bytes
コンパイル時間 17,544 ms
コンパイル使用メモリ 442,456 KB
実行使用メモリ 115,128 KB
最終ジャッジ日時 2024-04-22 13:11:52
合計ジャッジ時間 37,494 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 311 ms
51,552 KB
testcase_01 AC 314 ms
51,544 KB
testcase_02 AC 307 ms
51,828 KB
testcase_03 WA -
testcase_04 AC 313 ms
51,664 KB
testcase_05 WA -
testcase_06 AC 311 ms
51,612 KB
testcase_07 AC 309 ms
51,544 KB
testcase_08 WA -
testcase_09 AC 979 ms
101,236 KB
testcase_10 AC 1,003 ms
101,788 KB
testcase_11 AC 847 ms
94,576 KB
testcase_12 AC 954 ms
101,464 KB
testcase_13 AC 619 ms
68,948 KB
testcase_14 AC 874 ms
97,440 KB
testcase_15 AC 329 ms
51,884 KB
testcase_16 AC 800 ms
92,868 KB
testcase_17 AC 874 ms
93,940 KB
testcase_18 AC 734 ms
86,996 KB
testcase_19 AC 875 ms
96,272 KB
testcase_20 AC 558 ms
63,952 KB
testcase_21 AC 802 ms
92,568 KB
testcase_22 AC 681 ms
74,940 KB
testcase_23 AC 512 ms
58,512 KB
testcase_24 AC 553 ms
62,860 KB
testcase_25 AC 540 ms
62,216 KB
testcase_26 AC 995 ms
101,352 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 871 ms
115,128 KB
testcase_31 AC 904 ms
110,868 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:33:10: warning: parameter 'args' is never used
fun main(args : Array<String>) {
         ^

ソースコード

diff #

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")
}
0