結果
問題 | No.1207 グラフX |
ユーザー | WSKR |
提出日時 | 2020-09-22 22:25:40 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,422 bytes |
コンパイル時間 | 213 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 73,988 KB |
最終ジャッジ日時 | 2024-06-26 22:11:03 |
合計ジャッジ時間 | 74,308 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 1,598 ms
48,580 KB |
testcase_09 | AC | 1,839 ms
59,076 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | AC | 1,641 ms
51,900 KB |
testcase_13 | AC | 787 ms
20,992 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 1,749 ms
57,080 KB |
testcase_16 | AC | 794 ms
24,448 KB |
testcase_17 | AC | 1,334 ms
45,312 KB |
testcase_18 | AC | 1,214 ms
46,592 KB |
testcase_19 | AC | 1,200 ms
33,116 KB |
testcase_20 | TLE | - |
testcase_21 | AC | 157 ms
11,136 KB |
testcase_22 | AC | 1,356 ms
46,292 KB |
testcase_23 | AC | 1,502 ms
52,184 KB |
testcase_24 | AC | 1,064 ms
42,516 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 1,619 ms
55,572 KB |
testcase_27 | AC | 1,909 ms
64,728 KB |
testcase_28 | AC | 1,794 ms
59,204 KB |
testcase_29 | AC | 1,822 ms
64,228 KB |
testcase_30 | AC | 866 ms
32,000 KB |
testcase_31 | AC | 659 ms
17,408 KB |
testcase_32 | AC | 795 ms
33,600 KB |
testcase_33 | AC | 840 ms
32,768 KB |
testcase_34 | AC | 1,708 ms
56,320 KB |
testcase_35 | AC | 159 ms
11,904 KB |
testcase_36 | AC | 1,733 ms
58,496 KB |
testcase_37 | AC | 1,488 ms
48,212 KB |
testcase_38 | AC | 388 ms
20,096 KB |
testcase_39 | AC | 889 ms
35,252 KB |
testcase_40 | AC | 519 ms
12,416 KB |
testcase_41 | AC | 1,123 ms
33,792 KB |
testcase_42 | AC | 29 ms
11,008 KB |
testcase_43 | AC | 30 ms
10,880 KB |
testcase_44 | AC | 30 ms
10,880 KB |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | TLE | - |
testcase_48 | TLE | - |
ソースコード
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * (n+1) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n + 1) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) mod = 10 ** 9 + 7 def main(): N, M, X = map(int, input().split()) weight_cost = [0 for i in range(N+1)] Uni = UnionFind(N) res = 0 que = [] G = [[] for i in range(N+1)] for i in range(M): x, y, z = map(int, input().split()) if Uni.same(x, y) == True: continue else: Uni.union(x, y) G[x].append(y) G[y].append(x) que.append((x, y, z)) #ここで得られる構造は木構造 visited = [False for i in range(N+1)] depth = [0 for i in range(N+1)] child_cnt = [1 for i in range(N+1)] def dfs(s_node): visited[s_node] = True for node in G[s_node]: if visited[node] == False: depth[node] = depth[s_node] + 1 dfs(node) for node in G[s_node]: if depth[node] > depth[s_node]: child_cnt[s_node] += child_cnt[node] dfs(1) for x, y, z in que: if depth[x] > depth[y]: res += pow(X, z, mod) * child_cnt[x]*(N-child_cnt[x]) res %= mod else: res += pow(X, z, mod) * child_cnt[y]*(N-child_cnt[y]) res %= mod print(res) return if __name__ == "__main__": main()