結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー |
|
提出日時 | 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 |
ソースコード
import scala.collection.mutableimport 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 dograph(f) ::= tgraph(t) ::= fval u = readLine().toIntval 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) = truefor i <- closed dovisit(i) = truewhile stack.nonEmpty doval current = stack.removeLast()for next <- graph(current) doif !visit(next) thenvisit(next) = truestack.addOne(next)println(if (visit(g)) "Yes" else "No")