結果
| 問題 | No.1190 Points |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-22 15:52:40 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,148 bytes |
| 記録 | |
| コンパイル時間 | 15,436 ms |
| コンパイル使用メモリ | 437,964 KB |
| 実行使用メモリ | 127,276 KB |
| 最終ジャッジ日時 | 2024-10-15 10:02:59 |
| 合計ジャッジ時間 | 42,087 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 16 |
ソースコード
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()
}