complete 13265.kt 21208.kt
This commit is contained in:
65
storage/zeta/kt/completed/13265.kt
Normal file
65
storage/zeta/kt/completed/13265.kt
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
fun canBipartitioned(n: Int, edges: List<List<Int>>): Boolean {
|
||||||
|
val colored = MutableList(n) { false }
|
||||||
|
val visited = MutableList(n) { false }
|
||||||
|
|
||||||
|
val deq = mutableListOf<Pair<Int, Boolean>>()
|
||||||
|
|
||||||
|
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<List<Int>> = (1..m).map {
|
||||||
|
readln().split(' ').map { i -> i.toInt() }.let {
|
||||||
|
Pair(it[0] - 1, it[1] - 1)
|
||||||
|
}
|
||||||
|
}.let {
|
||||||
|
val res: MutableList<MutableList<Int>> = 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"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
27
storage/zeta/kt/completed/21208.kt
Normal file
27
storage/zeta/kt/completed/21208.kt
Normal file
@@ -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<String, Record>()
|
||||||
|
|
||||||
|
(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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user