結果

問題 No.1480 Many Complete Graphs
ユーザー mkawa2mkawa2
提出日時 2022-11-04 17:51:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 86,600 KB
実行使用メモリ 96,820 KB
最終ジャッジ日時 2023-09-25 20:26:38
合計ジャッジ時間 18,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,168 KB
testcase_01 AC 77 ms
70,976 KB
testcase_02 AC 78 ms
71,036 KB
testcase_03 AC 79 ms
71,072 KB
testcase_04 AC 79 ms
70,944 KB
testcase_05 AC 78 ms
70,944 KB
testcase_06 AC 79 ms
70,940 KB
testcase_07 AC 79 ms
71,040 KB
testcase_08 AC 79 ms
70,868 KB
testcase_09 AC 104 ms
76,724 KB
testcase_10 AC 94 ms
76,316 KB
testcase_11 AC 80 ms
70,868 KB
testcase_12 AC 86 ms
76,016 KB
testcase_13 AC 108 ms
82,868 KB
testcase_14 AC 104 ms
80,704 KB
testcase_15 AC 255 ms
85,628 KB
testcase_16 AC 196 ms
84,040 KB
testcase_17 AC 207 ms
83,900 KB
testcase_18 AC 148 ms
82,444 KB
testcase_19 AC 199 ms
83,148 KB
testcase_20 AC 230 ms
83,212 KB
testcase_21 AC 109 ms
81,460 KB
testcase_22 AC 96 ms
77,080 KB
testcase_23 AC 123 ms
84,044 KB
testcase_24 AC 226 ms
82,940 KB
testcase_25 AC 299 ms
87,540 KB
testcase_26 AC 291 ms
88,960 KB
testcase_27 AC 223 ms
83,424 KB
testcase_28 AC 218 ms
96,440 KB
testcase_29 AC 214 ms
96,324 KB
testcase_30 AC 215 ms
96,436 KB
testcase_31 AC 220 ms
96,384 KB
testcase_32 AC 215 ms
96,712 KB
testcase_33 AC 219 ms
96,568 KB
testcase_34 AC 222 ms
96,624 KB
testcase_35 AC 266 ms
96,560 KB
testcase_36 AC 265 ms
96,476 KB
testcase_37 AC 256 ms
96,384 KB
testcase_38 AC 275 ms
96,420 KB
testcase_39 AC 277 ms
96,356 KB
testcase_40 AC 251 ms
96,496 KB
testcase_41 AC 253 ms
96,352 KB
testcase_42 AC 274 ms
96,820 KB
testcase_43 AC 296 ms
96,624 KB
testcase_44 AC 291 ms
96,612 KB
testcase_45 AC 281 ms
96,700 KB
testcase_46 AC 285 ms
96,616 KB
testcase_47 AC 386 ms
94,904 KB
testcase_48 AC 333 ms
94,712 KB
testcase_49 AC 329 ms
94,052 KB
testcase_50 AC 160 ms
90,928 KB
testcase_51 AC 397 ms
94,508 KB
testcase_52 AC 318 ms
93,256 KB
testcase_53 AC 379 ms
93,956 KB
testcase_54 AC 383 ms
94,240 KB
testcase_55 AC 380 ms
94,052 KB
testcase_56 AC 361 ms
93,576 KB
testcase_57 AC 177 ms
90,680 KB
testcase_58 AC 158 ms
91,568 KB
evil_aftercontest.txt AC 218 ms
108,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

from heapq import *

n, m = LI()

gg = [[] for _ in range(n+1)]
cc = []
mem = []
for g in range(m):
    k, c, *ss = LI()
    cc.append(c)
    mem.append(ss[::-1])
    for s in ss:
        gg[s].append(g)

hp = []
dist = [inf]*(n+1)
dist[1] = 0
mns = [inf]*m
mnu = [-1]*m
fin = [0]*(n+1)
fin[1] = 1
for g in gg[1]:
    mns[g] = 1
    mnu[g] = 1
    mem[g].pop()
    v = mem[g][-1]
    d = (v+2)//2+cc[g]
    dist[v] = d
    heappush(hp, (d, v))

def update(g):
    while mem[g] and fin[mem[g][-1]]: mem[g].pop()
    if not mem[g]: return
    u = mnu[g]
    v = mem[g][-1]
    nd = dist[u]+(u+v+1)//2+cc[g]
    if nd < dist[v]:
        dist[v] = nd
        heappush(hp, (nd, v))

while hp:
    d, u = heappop(hp)
    if u == n: break
    if d > dist[u]: continue
    fin[u] = 1
    for g in gg[u]:
        cur = d*2+u
        if cur < mns[g]: mns[g], mnu[g] = cur, u
        update(g)
        # pDB(hp, mem)

ans = dist[-1]
if ans == inf: ans = -1
print(ans)
0