結果

問題 No.1207 グラフX
ユーザー ああいいああいい
提出日時 2022-01-27 17:40:47
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 919 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 86,752 KB
実行使用メモリ 840,980 KB
最終ジャッジ日時 2023-08-26 18:44:08
合計ジャッジ時間 18,305 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 769 ms
138,620 KB
testcase_01 AC 604 ms
138,824 KB
testcase_02 AC 546 ms
140,144 KB
testcase_03 AC 562 ms
139,204 KB
testcase_04 AC 633 ms
138,580 KB
testcase_05 AC 1,033 ms
311,748 KB
testcase_06 AC 1,122 ms
321,880 KB
testcase_07 AC 1,090 ms
320,712 KB
testcase_08 AC 587 ms
118,744 KB
testcase_09 AC 622 ms
131,032 KB
testcase_10 MLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)

N,M,X = map(int,input().split())
G = [[] for _ in range(N+1)]
P = 10 ** 9 + 7
edge = []
parent = list(range(N+1))
def find(i):
    if parent[i] == i:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    parent[I] = J
    parent[i] = J
    return True
def isSame(i,j):
    return find(i) == find(j)

for _ in range(M):
    x,y,z = map(int,input().split())
    if isSame(x,y):
        continue
    else:
        unite(x,y)
        G[x].append(y)
        G[y].append(x)
        edge.append((x,y,z))
child = [1] * (N + 1)
def dfs(now = 1,p = 0):
    for v in G[now]:
        if v == p:continue
        dfs(v,now)
        child[now] += child[v]
dfs()
ans = 0
for x,y,z in edge:
    if child[x] > child[y]:
        x,y = y,x
    ans = (ans + child[x] * (N-child[x]) * pow(X,z,P)) % P
print(ans)
0