Submission #1518226


Source Code Expand

import java.util.Scanner

import scala.collection.mutable

object Main {
  def solve(sc: => Scanner): Unit = {
    val N, M = sc.nextInt
    val S, T = sc.nextInt - 1
    val mapping = Array.fill[List[Int]](N)(List())
    for (i <- 0 until M) {
      val x, y = sc.nextInt - 1
      mapping(x).+:=(y)
      mapping(y).+:=(x)
    }
    System.gc()
    val len1 = Array.fill[Int](N)(Int.MaxValue / 6)
    len1(S) = 0
    val que1 = mutable.Queue[Int](S)
    while (que1.size != 0) {
      val now = que1.dequeue()
      for (next <- mapping(now)) {
        if (len1(next) > len1(now) + 1 && len1(now) + 1 <= len1(T)) {
          len1(next) = len1(now) + 1
          que1.enqueue(next)
        }
      }
    }
    System.gc()
    val lenST = len1(T) - 2
    val len2 = Array.fill[Int](N)(Int.MaxValue / 6)
    len2(T) = 0
    val que2 = mutable.Queue[Int](T)
    while (que2.size != 0) {
      val now = que2.dequeue()
      for (next <- mapping(now)) {
        if (len2(next) > len2(now) + 1 && len2(now) + 1 <= lenST) {
          len2(next) = len2(now) + 1
          que2.enqueue(next)
        }
      }
    }
    System.gc()
    val list1g = len1.filter(x => x <= lenST).groupBy(x => x)
    val list2g = len2.filter(x => x <= lenST).groupBy(x => x)
    System.gc()
    var ans = 0
    for (i <- 0 to lenST) {
      val j = lenST - i
      ans += list1g(i).length * list2g(j).length
    }
    println(ans)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Submission Info

Submission Time
Task B - Minus One
User goryudyuma
Language Scala (2.11.7)
Score 0
Code Size 1573 Byte
Status TLE
Exec Time 2046 ms
Memory 145440 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 62
TLE × 2
MLE × 9
Set Name Test Cases
All 00-sample1.txt, 00-sample2.txt, 00-sample4.txt, 50-random10.txt, 50-random11.txt, 50-random12.txt, 50-random13.txt, 50-random14.txt, 50-random15.txt, 50-random16.txt, 50-random17.txt, 50-random18.txt, 50-random19.txt, 50-random20.txt, 50-random21.txt, 50-random22.txt, 50-random23.txt, 50-random24.txt, 50-random25.txt, 50-random26.txt, 50-random27.txt, 50-random28.txt, 50-random29.txt, 50-random30.txt, 50-random31.txt, 50-random32.txt, 50-random33.txt, 50-random34.txt, 50-random35.txt, 50-random36.txt, 50-random37.txt, 50-random38.txt, 50-random39.txt, 50-random40.txt, 50-random41.txt, 50-random42.txt, 50-random43.txt, 50-random44.txt, 50-random45.txt, 50-random46.txt, 50-random47.txt, 50-random48.txt, 50-random49.txt, 50-random50.txt, 50-random51.txt, 50-random52.txt, 50-random53.txt, 50-random54.txt, 50-random55.txt, 50-random56.txt, 50-random57.txt, 50-random58.txt, 50-random59.txt, 50-random60.txt, 50-random61.txt, 50-random62.txt, 50-random63.txt, 50-random64.txt, 50-random65.txt, 50-random66.txt, 50-random67.txt, 50-random68.txt, 50-random69.txt, intoverflow00.txt, intoverflow01.txt, intoverflow02.txt, intoverflow03.txt, intoverflow04.txt, intoverflow05.txt, intoverflow06.txt, intoverflow07.txt, intoverflow08.txt, intoverflow09.txt
Case Name Status Exec Time Memory
00-sample1.txt AC 410 ms 42568 KB
00-sample2.txt AC 412 ms 38464 KB
00-sample4.txt AC 412 ms 42296 KB
50-random10.txt AC 431 ms 38568 KB
50-random11.txt AC 405 ms 38340 KB
50-random12.txt AC 412 ms 42168 KB
50-random13.txt AC 419 ms 38328 KB
50-random14.txt AC 406 ms 38476 KB
50-random15.txt AC 406 ms 42284 KB
50-random16.txt AC 403 ms 41916 KB
50-random17.txt AC 408 ms 40508 KB
50-random18.txt AC 415 ms 40504 KB
50-random19.txt AC 405 ms 42564 KB
50-random20.txt AC 407 ms 38464 KB
50-random21.txt AC 404 ms 40272 KB
50-random22.txt AC 411 ms 40380 KB
50-random23.txt AC 412 ms 42300 KB
50-random24.txt AC 411 ms 40256 KB
50-random25.txt AC 405 ms 40252 KB
50-random26.txt AC 406 ms 38336 KB
50-random27.txt AC 406 ms 38336 KB
50-random28.txt AC 408 ms 38344 KB
50-random29.txt AC 414 ms 40388 KB
50-random30.txt AC 411 ms 40124 KB
50-random31.txt AC 405 ms 38196 KB
50-random32.txt AC 412 ms 38320 KB
50-random33.txt AC 419 ms 40384 KB
50-random34.txt AC 428 ms 41016 KB
50-random35.txt AC 408 ms 40516 KB
50-random36.txt AC 425 ms 40496 KB
50-random37.txt AC 423 ms 42924 KB
50-random38.txt AC 424 ms 40516 KB
50-random39.txt AC 414 ms 38208 KB
50-random40.txt AC 610 ms 47612 KB
50-random41.txt AC 465 ms 42424 KB
50-random42.txt AC 499 ms 42800 KB
50-random43.txt AC 431 ms 40368 KB
50-random44.txt AC 498 ms 45480 KB
50-random45.txt AC 436 ms 40484 KB
50-random46.txt AC 521 ms 42964 KB
50-random47.txt AC 525 ms 45036 KB
50-random48.txt AC 546 ms 42076 KB
50-random49.txt AC 561 ms 41900 KB
50-random50.txt AC 735 ms 48856 KB
50-random51.txt AC 847 ms 53396 KB
50-random52.txt AC 639 ms 47264 KB
50-random53.txt AC 858 ms 53320 KB
50-random54.txt AC 872 ms 54000 KB
50-random55.txt AC 913 ms 55036 KB
50-random56.txt AC 527 ms 41500 KB
50-random57.txt AC 729 ms 50048 KB
50-random58.txt AC 747 ms 47296 KB
50-random59.txt AC 679 ms 49972 KB
50-random60.txt AC 1469 ms 93356 KB
50-random61.txt AC 1258 ms 95716 KB
50-random62.txt MLE 1605 ms 137552 KB
50-random63.txt AC 1324 ms 97044 KB
50-random64.txt AC 1441 ms 95456 KB
50-random65.txt AC 1084 ms 66004 KB
50-random66.txt AC 1176 ms 58432 KB
50-random67.txt AC 913 ms 51332 KB
50-random68.txt AC 802 ms 51496 KB
50-random69.txt AC 750 ms 47564 KB
intoverflow00.txt MLE 1939 ms 144524 KB
intoverflow01.txt MLE 1956 ms 143736 KB
intoverflow02.txt MLE 1939 ms 145440 KB
intoverflow03.txt MLE 1930 ms 141352 KB
intoverflow04.txt MLE 1953 ms 144696 KB
intoverflow05.txt MLE 1999 ms 139260 KB
intoverflow06.txt TLE 2017 ms 141964 KB
intoverflow07.txt TLE 2046 ms 142160 KB
intoverflow08.txt MLE 1937 ms 144004 KB
intoverflow09.txt MLE 1947 ms 143620 KB