結果

問題 No.1190 Points
ユーザー 👑 箱星箱星
提出日時 2020-08-22 15:52:40
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 2,148 bytes
コンパイル時間 13,911 ms
コンパイル使用メモリ 457,976 KB
実行使用メモリ 128,996 KB
最終ジャッジ日時 2024-04-23 10:09:31
合計ジャッジ時間 35,694 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
57,076 KB
testcase_01 AC 251 ms
54,124 KB
testcase_02 AC 279 ms
56,832 KB
testcase_03 AC 773 ms
105,016 KB
testcase_04 AC 718 ms
104,184 KB
testcase_05 AC 730 ms
104,640 KB
testcase_06 AC 813 ms
106,484 KB
testcase_07 AC 1,003 ms
118,956 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 848 ms
121,604 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 398 ms
68,472 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 408 ms
73,872 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 781 ms
120,468 KB
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val p = sc.nextInt()
    val s = sc.nextInt() - 1
    val g = sc.nextInt() - 1
    val adj = Array(n) { mutableSetOf<Int>() }
    for (i in 0 until m) {
        val v1 = sc.nextInt() - 1
        val v2 = sc.nextInt() - 1
        adj[v1].add(v2)
        adj[v2].add(v1)
    }
    val dist = IntArray(n) { 0 }
    val que: Queue<Pair<Int, Int>> = ArrayDeque()
    val visited = BooleanArray(n) { false }
    visited[s] = true
    que.add(s to 0)
    while (que.count() > 0) {
        val (v, step) = que.poll()
        dist[v] = step
        for (w in adj[v]) {
            if (visited[w]) continue
            que.add(w to step + 1)
            visited[w] = true
        }
    }
    if (p % 2 != dist[g] % 2 || dist[g] > p) {
        println(-1)
        return
    }
    val dist2 = IntArray(n) { 0 }
    que.clear()
    que.add(g to 0)
    for (i in 0 until n) {
        visited[i] = i == g
    }
    while (que.count() > 0) {
        val (v, step) = que.poll()
        dist2[v] = step
        for (w in adj[v]) {
            if (visited[w]) continue
            que.add(w to step + 1)
            visited[w] = true
        }
    }
    val lst = mutableListOf<Int>()
    for (i in 0 until n) {
        if (dist[i] + dist2[i] <= p) {
            lst.add(i + 1)
        }
    }
    println(lst.count())
    println(lst.joinToString("\n"))
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}
0