結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー mkawa2mkawa2
提出日時 2020-12-18 18:22:02
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,576 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,632 KB
実行使用メモリ 82,684 KB
最終ジャッジ日時 2023-10-21 08:12:03
合計ジャッジ時間 4,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
60,524 KB
testcase_01 AC 34 ms
53,464 KB
testcase_02 AC 34 ms
53,464 KB
testcase_03 AC 35 ms
53,464 KB
testcase_04 AC 33 ms
53,464 KB
testcase_05 AC 38 ms
58,744 KB
testcase_06 AC 40 ms
58,744 KB
testcase_07 AC 61 ms
68,332 KB
testcase_08 AC 63 ms
72,472 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16
# md = 998244353
md = 10**9+7

t = II()
n, m = MI()
to = [[] for _ in range(n)]
for _ in range(m):
    u, v, w = MI()
    u, v = u-1, v-1
    to[u].append((v, w))
    if t == 0:
        to[v].append((u, w))

vis = [-1]*n
dist = [-1]*n
def dfs(u):
    dist[u] = 0
    stack = [(u,-1,0)]
    res = inf
    while stack:
        u,pu,d = stack.pop()
        # print(u,pu,d,dist,stack)
        dist[u]=d
        if vis[u] == 0:
            vis[u] = -1
        else:
            vis[u] = 0
            stack.append((u,pu,d))
            for v, w in to[u]:
                if v==pu:continue
                if vis[v] == 0:
                    # print(u,v,d+w-dist[v])
                    res = min(res, d+w-dist[v])
                elif vis[v] == -1:
                    stack.append((v,u,d+w))
    return res

ans=inf
for u in range(n):
    if vis[u]==1:continue
    ans=min(ans,dfs(u))

if ans==inf:print(-1)
else:print(ans)
0