結果

問題 No.848 なかよし旅行
ユーザー HaarHaar
提出日時 2020-06-19 01:46:34
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 1,755 bytes
コンパイル時間 3,850 ms
コンパイル使用メモリ 72,812 KB
実行使用メモリ 11,748 KB
最終ジャッジ日時 2023-09-16 12:33:25
合計ジャッジ時間 6,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 WA -
testcase_23 RE -
testcase_24 WA -
testcase_25 RE -
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(7, 8) Warning: imported and not used: 'strformat' [UnusedImport]

ソースコード

diff #

import strutils
import macros
import typetraits
import options
import heapqueue
import sequtils
import strformat


type
  Edge*[T] = object
    to*: int
    cost*: T
  
  Graph*[T] = seq[seq[Edge[T]]]

proc make*[T](t: typedesc[Graph[T]], size: int): Graph[T] {.noSideEffect.} =
  return Graph[T](newSeq[seq[Edge[T]]](size))

proc add_edge*[T](g: var Graph[T], s, t: int, c: T) = g[s].add(Edge[T](to: t, cost: c))

proc dijkstra*[T](g: Graph[T], s: int): seq[Option[T]] =
  let N = g.len
  var dist = newSeq[Option[T]](N)
  var check = newSeq[bool](N)
  var heap = initHeapQueue[(T, int)]()

  heap.push((T(0), s))

  while heap.len != 0:
    let (d, i) = heap.pop

    if check[i]: break
    check[i] = true

    for e in g[i]:
      if dist[e.to].isNone:
        dist[e.to] = some(d + e.cost)
        heap.push((dist[e.to].get, e.to))

      elif dist[i].get + e.cost < dist[e.to].get:
        dist[e.to] = some(dist[i].get + e.cost)
        heap.push((dist[e.to].get, e.to))

  return dist





let res = stdin.readline.split.mapIt(it.parseInt)
let N = res[0]
let M = res[1]
let P = res[2] - 1
let Q = res[3] - 1
let T = res[4]

var g = Graph[int64].make(N)

for i in 0 ..< M:
  let res = stdin.readline.split.mapIt(it.parseInt)
  let a = res[0] - 1
  let b = res[1] - 1
  let c = res[2]

  g.add_edge(a, b, c)
  g.add_edge(b, a, c)




let dist0 = g.dijkstra(0)
let distp = g.dijkstra(P)
let distq = g.dijkstra(Q)

var ans: int64 = -1

if dist0[P].get + distp[Q].get + distq[P].get <= T:
  ans = max(ans, T)

for i in 0 ..< N:
  for j in 0 ..< N:
    if dist0[i].get + max(distp[i].get + distp[j].get, distq[i].get + distq[j].get) + dist0[j].get <= T:
      ans = max(ans, T - max(distp[i].get + distp[j].get, distq[i].get + distq[j].get))

echo ans

0