結果
| 問題 |
No.977 アリス仕掛けの摩天楼
|
| コンテスト | |
| ユーザー |
rhincodon66
|
| 提出日時 | 2020-01-31 22:45:56 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 941 bytes |
| コンパイル時間 | 12,798 ms |
| コンパイル使用メモリ | 453,628 KB |
| 実行使用メモリ | 85,540 KB |
| 最終ジャッジ日時 | 2024-09-17 09:40:44 |
| 合計ジャッジ時間 | 25,923 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 2 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args:Array<String>){
^
Main.kt:38:5: warning: a function is marked as tail-recursive but no tail calls are found
tailrec fun find(x : Int) : Int{
^
Main.kt:40:16: warning: recursive call is not a tail call
a[x] = find(a[x])
^
ソースコード
import java.util.*
fun main(args:Array<String>){
val n = readLine()!!.toInt()
val uf = UnionFind(n)
repeat(n - 1){
val (a,b) = readLine()!!.split(" ").map{it.toInt()}
uf.unite(a,b)
}
val a = uf.find(0)
var ok = true
for(i in 0 until n){
if(uf.find(i) != a) ok = false
}
println(if(ok) "Bob" else "Alice")
}
class UnionFind{
var a = IntArray(0)
constructor(n : Int){
this.a = IntArray(n){-1}
}
fun unite(x : Int, y : Int) : Boolean{
var X = find(x)
var Y = find(y)
if(X == Y) return false
if(a[X] > a[Y]){
val Z = X
X = Y
Y = Z
}
a[X] += a[Y]
a[Y] = X
return true
}
tailrec fun find(x : Int) : Int{
if(a[x] < 0) return x
a[x] = find(a[x])
return a[x]
}
fun size(x : Int) : Int{
return -a[find(x)]
}
}
rhincodon66