ログインしてください。
提出 #37821821
ソースコード 拡げる
fun main() {
val (N, M) = readLineSplit { toInt() }
val group = Array(N) { Group(-1) }
var newGroup = Group(0)
for(i in 0 until M) {
val (u, v) = readLineSplit { toInt() - 1 }
when {
group[u].id == -1 && group[v].id == -1 -> {
group[u] = newGroup
group[v] = newGroup
newGroup = Group(newGroup.id+1)
}
group[u].id == -1 && group[v].id != -1 -> group[u] = group[v]
group[u].id != -1 && group[v].id == -1 -> group[v] = group[u]
group[u].id != group[v].id -> group[u].id = group[v].id
}
}
val ans = group.count { it.id == -1 } + group.filterNot{ it.id == -1 }.distinctBy { it.id }.size
println(ans)
}
fun <T> readLineSplit(cast: String.() -> T): List<T> = readLine()!!.split(" ").map { it.cast() }
class Group(var id: Int)
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Count Connected Components |
| ユーザ | YusukeK |
| 言語 | Kotlin (1.3.71) |
| 得点 | 0 |
| コード長 | 903 Byte |
| 結果 | WA |
| 実行時間 | 179 ms |
| メモリ | 40988 KiB |
コンパイルエラー
warning: ATTENTION! This build uses unsafe internal compiler arguments: -XXLanguage:+InlineClasses This mode is not recommended for production use, as no stability/compatibility guarantees are given on compiler or generated code. Use it at your own risk!
ジャッジ結果
| セット名 | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 0 / 300 | ||||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_corner_00.txt, 02_corner_01.txt, 02_corner_02.txt, 03_path_00.txt, 04_perfect_00.txt, 05_m_eq_0_00.txt, 06_n_eq_1_00.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 112 ms | 36304 KiB |
| 00_sample_01.txt | AC | 103 ms | 36340 KiB |
| 00_sample_02.txt | AC | 99 ms | 36184 KiB |
| 01_random_00.txt | WA | 114 ms | 36048 KiB |
| 01_random_01.txt | AC | 115 ms | 36336 KiB |
| 01_random_02.txt | WA | 106 ms | 36176 KiB |
| 01_random_03.txt | WA | 120 ms | 37800 KiB |
| 01_random_04.txt | AC | 106 ms | 36048 KiB |
| 01_random_05.txt | AC | 108 ms | 36396 KiB |
| 01_random_06.txt | AC | 148 ms | 38800 KiB |
| 01_random_07.txt | AC | 147 ms | 38308 KiB |
| 01_random_08.txt | AC | 129 ms | 37948 KiB |
| 01_random_09.txt | AC | 124 ms | 38076 KiB |
| 02_corner_00.txt | AC | 118 ms | 37964 KiB |
| 02_corner_01.txt | AC | 127 ms | 37960 KiB |
| 02_corner_02.txt | AC | 127 ms | 38096 KiB |
| 03_path_00.txt | AC | 123 ms | 37764 KiB |
| 04_perfect_00.txt | AC | 179 ms | 40988 KiB |
| 05_m_eq_0_00.txt | AC | 104 ms | 36360 KiB |
| 06_n_eq_1_00.txt | AC | 103 ms | 36204 KiB |