結果

問題 No.860 買い物
ユーザー 6soukiti296soukiti29
提出日時 2019-08-16 23:28:17
言語 Nim
(2.0.2)
結果
TLE  
実行時間 -
コード長 1,235 bytes
コンパイル時間 3,383 ms
コンパイル使用メモリ 71,384 KB
実行使用メモリ 27,840 KB
最終ジャッジ日時 2023-09-15 12:34:52
合計ジャッジ時間 8,122 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
27,840 KB
testcase_01 AC 3 ms
4,512 KB
testcase_02 AC 3 ms
4,596 KB
testcase_03 AC 3 ms
4,668 KB
testcase_04 AC 3 ms
4,700 KB
testcase_05 AC 3 ms
4,592 KB
testcase_06 AC 8 ms
5,420 KB
testcase_07 AC 166 ms
23,436 KB
testcase_08 AC 165 ms
23,480 KB
testcase_09 AC 164 ms
23,476 KB
testcase_10 AC 166 ms
23,428 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,strutils,algorithm
type
    unionfindtree[I : static[int]] = array[I,int]

proc initUT(I : static[int]):unionfindtree[I] =
    var res : unionfindtree[I]
    for i in 0..<I:
        res[i] = i
    return res
    
proc find(U : unionfindtree; a : int, b :int): bool=
    var
        s = a
        t = b
    while s != U[s]:
        s = U[s]
    while t != U[t]:
        t = U[t]
    return s == t
    
proc union(U : var  unionfindtree; a : int ; b : int)=
    if U.find(a,b):
        return
    var
        s = a
        t = b
        t2 : int
    while s != U[s]:
        s = U[s]
    while t != U[t]:
        t2 = U[t]
        U[t] = s
        t = t2
    U[t] = s
proc root(U : unionfindtree, a :int):int=
    var
        s = a
    while s != U[s]:
        s = U[s]
    return s

var
    N = stdin.readline.parseInt
    BIT = initUT(100010)
    c,d,ans : int

type
    edge = tuple[a,b,c : int]

var
    edges = newSeq[edge](0)

for i in 1..N:
    (c, d) =stdin.readline.split.map(parseInt)
    if i != 1:
        edges.add((i, i - 1, d))
    edges.add((i, 0, c))
    ans += c

edges = edges.sortedByIt(it.c)
for e in edges:
    if BIT.find(e.a,e.b) == false:
        ans += e.c
        BIT.union(e.a,e.b)

echo ans

0