結果
問題 |
No.1190 Points
|
ユーザー |
|
提出日時 | 2020-08-22 14:42:36 |
言語 | Kotlin (2.1.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,004 bytes |
コンパイル時間 | 15,457 ms |
コンパイル使用メモリ | 456,988 KB |
実行使用メモリ | 162,232 KB |
最終ジャッジ日時 | 2024-10-15 08:56:48 |
合計ジャッジ時間 | 25,346 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 19 |
コンパイルメッセージ
Main.kt:24:23: warning: name shadowed: p val (v, step, p) = que.poll() ^ Main.kt:39:23: warning: name shadowed: p val (v, step, p) = que.poll() ^
ソースコード
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<Triple<Int, Int, Int>> = ArrayDeque() que.add(Triple(s, 0, -1)) while (que.count() > 0) { val (v, step, p) = que.poll() dist[v] = step for (w in adj[v]) { if (w == p) continue que.add(Triple(w, step + 1, v)) } } if (p % 2 != dist[g] % 2 || dist[g] > p) { println(-1) return } val dist2 = IntArray(n) { 0 } que.clear() que.add(Triple(g, 0, -1)) while (que.count() > 0) { val (v, step, p) = que.poll() dist2[v] = step for (w in adj[v]) { if (w == p) continue que.add(Triple(w, step + 1, v)) } } 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() }