From 5907d7f7c870eb2ee0e0ec9d6818b30f0ca393f8 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Mon, 7 Jul 2025 17:42:25 +0900 Subject: [PATCH] complete 13265.kt 21208.kt --- storage/zeta/kt/completed/13265.kt | 65 ++++++++++++++++++++++++++++++ storage/zeta/kt/completed/21208.kt | 27 +++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 storage/zeta/kt/completed/13265.kt create mode 100644 storage/zeta/kt/completed/21208.kt diff --git a/storage/zeta/kt/completed/13265.kt b/storage/zeta/kt/completed/13265.kt new file mode 100644 index 0000000..d1e0f79 --- /dev/null +++ b/storage/zeta/kt/completed/13265.kt @@ -0,0 +1,65 @@ +fun canBipartitioned(n: Int, edges: List>): Boolean { + val colored = MutableList(n) { false } + val visited = MutableList(n) { false } + + val deq = mutableListOf>() + + var deadFlag = false + (0 until n).forEach { + deq.add(Pair(it, true)) + } + + while (deq.isNotEmpty()) { + val (node, beforeColor) = deq.removeLast() + if (visited[node]) { + continue + } + visited[node] = true + val nowColor = !beforeColor + colored[node] = nowColor + + for (next in edges[node]) { + if (visited[next] && colored[next] == nowColor) { + deadFlag = true + break + } + + if (!visited[next]) { + deq.add(Pair(next, nowColor)) + } + } + + if (deadFlag) { + break + } + } + + return !deadFlag +} + + +fun main() = with(System.`in`.bufferedReader()) { + (1..readln().toInt()).forEach { _ -> + val (n /* 동그라미 개수*/, m/* 직선 개수*/) = readln().split(' ').map { i -> i.toInt() } + val edges: List> = (1..m).map { + readln().split(' ').map { i -> i.toInt() }.let { + Pair(it[0] - 1, it[1] - 1) + } + }.let { + val res: MutableList> = MutableList(n, { mutableListOf() }) + it.forEach { + res[it.first].add(it.second) + res[it.second].add(it.first) + } + res + } + + println( + if (canBipartitioned(n, edges)) { + "possible" + } else { + "impossible" + } + ) + } +} \ No newline at end of file diff --git a/storage/zeta/kt/completed/21208.kt b/storage/zeta/kt/completed/21208.kt new file mode 100644 index 0000000..edb834e --- /dev/null +++ b/storage/zeta/kt/completed/21208.kt @@ -0,0 +1,27 @@ +data class Record( + var counts: Int, + var lastModified: Int, +) + +fun main() = with(System.`in`.bufferedReader()) { + val (n, k) = readln().split(' ').map { i -> i.toInt() } + val history = mutableMapOf() + + (1..(3 * n)).forEach { i -> + val key = readln() + + if (key in history) { + history[key]?.let { + it.counts++ + it.lastModified = i + } + } else { + history[key] = Record(1, i) + } + } + + history.toList().sortedWith(compareBy({ it.second.counts }, { it.second.lastModified })).takeLast(k).reversed() + .forEach { item -> + println(item.first) + } +} \ No newline at end of file