結果

問題 No.1805 Approaching Many Typhoon
ユーザー yudedako
提出日時 2022-01-24 22:47:12
言語 Scala(Beta)
(3.6.2)
結果
AC  
実行時間 1,023 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 18,329 ms
コンパイル使用メモリ 272,916 KB
実行使用メモリ 65,736 KB
最終ジャッジ日時 2024-12-15 02:15:52
合計ジャッジ時間 52,647 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import scala.collection.mutable
import scala.io.StdIn.*
import scala.math.min

@main def main =
  val Array(n, m) = readLine().split(' ').map(_.toInt)
  val Array(s, g) = readLine().split(' ').map(_.toInt - 1)
  val edges = Array.fill(m){
    val Array(f, t) = readLine().split(' ').map(_.toInt - 1)
    (f, t)
  }
  val graph = Array.fill(n){Nil: List[Int]}
  for (f, t) <- edges do
    graph(f) ::= t
    graph(t) ::= f
  val u = readLine().toInt
  val closed = if u > 0 then readLine().split(' ').map(_.toInt - 1) else Array[Int]()
  val visit = Array.fill(n){false}
  val stack = mutable.ArrayDeque[Int]().addOne(s)
  visit(s) = true
  for i <- closed do
    visit(i) = true
  while stack.nonEmpty do
    val current = stack.removeLast()
    for next <- graph(current) do
      if !visit(next) then
        visit(next) = true
        stack.addOne(next)
  println(if (visit(g)) "Yes" else "No")
0