結果
問題 | No.1207 グラフX |
ユーザー | mkawa2 |
提出日時 | 2021-08-26 11:46:14 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,156 bytes |
コンパイル時間 | 509 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 134,856 KB |
最終ジャッジ日時 | 2024-11-18 08:53:36 |
合計ジャッジ時間 | 82,548 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | TLE | - |
testcase_02 | TLE | - |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | AC | 1,735 ms
96,476 KB |
testcase_09 | AC | 1,920 ms
106,688 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 1,664 ms
98,328 KB |
testcase_13 | AC | 747 ms
57,716 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 1,958 ms
105,268 KB |
testcase_16 | AC | 822 ms
56,900 KB |
testcase_17 | AC | 1,435 ms
83,672 KB |
testcase_18 | AC | 1,298 ms
77,392 KB |
testcase_19 | AC | 1,247 ms
78,580 KB |
testcase_20 | TLE | - |
testcase_21 | AC | 125 ms
18,816 KB |
testcase_22 | AC | 1,407 ms
84,152 KB |
testcase_23 | AC | 1,562 ms
92,284 KB |
testcase_24 | AC | 1,146 ms
70,852 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 1,714 ms
98,840 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 1,896 ms
108,068 KB |
testcase_29 | TLE | - |
testcase_30 | AC | 885 ms
59,688 KB |
testcase_31 | AC | 623 ms
51,268 KB |
testcase_32 | AC | 883 ms
56,340 KB |
testcase_33 | AC | 834 ms
57,196 KB |
testcase_34 | AC | 1,794 ms
103,624 KB |
testcase_35 | AC | 133 ms
19,168 KB |
testcase_36 | AC | 1,854 ms
104,156 KB |
testcase_37 | AC | 1,514 ms
89,744 KB |
testcase_38 | AC | 376 ms
32,164 KB |
testcase_39 | AC | 909 ms
60,464 KB |
testcase_40 | AC | 434 ms
43,648 KB |
testcase_41 | AC | 1,228 ms
73,076 KB |
testcase_42 | AC | 26 ms
10,880 KB |
testcase_43 | AC | 25 ms
11,008 KB |
testcase_44 | AC | 26 ms
11,008 KB |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | TLE | - |
testcase_48 | TLE | - |
ソースコード
import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] 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 = 10**9 # md = 998244353 md = 10**9+7 class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n # cntはグループ数 self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] return True # グループの要素数 def size(self, u): return self.size_table[self.root(u)] n, m, x = LI() xyz = LLI(m) to = [[] for _ in range(n)] uf = UnionFind(n) xyz.sort(key=lambda x: x[2]) for u, v, z in xyz: u, v = u-1, v-1 if not uf.merge(u, v): continue to[u].append((v, z)) to[v].append((u, z)) size = [1]*n ans = 0 stack = [(0, -1, True)] while stack: u, par, first = stack.pop() if first: stack.append((u, par, False)) for v, z in to[u]: if v == par: continue stack.append((v, u, True)) else: for v, z in to[u]: if v == par: continue ans += size[v]*(n-size[v])*pow(x, z, md)%md size[u] += size[v] ans %= md print(ans)