結果
問題 | No.1207 グラフX |
ユーザー | 双六 |
提出日時 | 2020-08-31 23:43:11 |
言語 | Python3 (3.11.6 + numpy 1.26.0 + scipy 1.11.3) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,606 bytes |
コンパイル時間 | 360 ms |
コンパイル使用メモリ | 10,952 KB |
実行使用メモリ | 154,240 KB |
最終ジャッジ日時 | 2023-08-10 18:13:17 |
合計ジャッジ時間 | 59,821 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,692 ms
104,440 KB |
testcase_01 | AC | 1,682 ms
104,936 KB |
testcase_02 | AC | 1,619 ms
105,380 KB |
testcase_03 | AC | 1,675 ms
104,504 KB |
testcase_04 | AC | 1,676 ms
104,932 KB |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | AC | 1,136 ms
62,356 KB |
testcase_09 | AC | 1,372 ms
73,432 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 1,147 ms
66,272 KB |
testcase_13 | AC | 428 ms
22,760 KB |
testcase_14 | AC | 1,597 ms
104,524 KB |
testcase_15 | AC | 1,279 ms
72,200 KB |
testcase_16 | AC | 482 ms
26,208 KB |
testcase_17 | AC | 961 ms
59,112 KB |
testcase_18 | AC | 889 ms
60,364 KB |
testcase_19 | AC | 764 ms
38,868 KB |
testcase_20 | AC | 1,595 ms
104,744 KB |
testcase_21 | AC | 73 ms
9,100 KB |
testcase_22 | AC | 998 ms
60,000 KB |
testcase_23 | AC | 1,141 ms
66,140 KB |
testcase_24 | AC | 793 ms
56,484 KB |
testcase_25 | AC | 1,609 ms
105,272 KB |
testcase_26 | AC | 1,176 ms
70,448 KB |
testcase_27 | AC | 1,425 ms
79,064 KB |
testcase_28 | AC | 1,314 ms
74,412 KB |
testcase_29 | AC | 1,380 ms
79,592 KB |
testcase_30 | AC | 604 ms
37,700 KB |
testcase_31 | AC | 342 ms
17,096 KB |
testcase_32 | AC | 566 ms
39,652 KB |
testcase_33 | AC | 576 ms
38,740 KB |
testcase_34 | AC | 1,230 ms
70,432 KB |
testcase_35 | AC | 78 ms
10,132 KB |
testcase_36 | AC | 1,252 ms
73,304 KB |
testcase_37 | AC | 1,057 ms
61,940 KB |
testcase_38 | AC | 269 ms
21,744 KB |
testcase_39 | AC | 636 ms
41,216 KB |
testcase_40 | AC | 231 ms
10,396 KB |
testcase_41 | AC | 722 ms
39,552 KB |
testcase_42 | AC | 17 ms
8,784 KB |
testcase_43 | AC | 17 ms
8,876 KB |
testcase_44 | AC | 16 ms
8,844 KB |
testcase_45 | AC | 1,558 ms
95,720 KB |
testcase_46 | AC | 1,552 ms
95,640 KB |
testcase_47 | AC | 1,574 ms
95,844 KB |
testcase_48 | AC | 1,601 ms
95,844 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class UnionFind: def __init__(self, n): self.par = [i for i in range(n + 1)] self.rank = [0] * (n + 1) def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def same_check(self, x, y): return self.find(x) == self.find(y) def union(self, x, y): x = self.find(x); y = self.find(y) if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) ans = 0 def DFS(N, G, W, visit, node, D, X): for i in G.graph[node]: if visit[i] != 1: visit[i] = 1 DFS(N, G, W, visit, i, D, X) W[node] += W[i] global ans ans += ((N - W[i]) * W[i] * pow(X, D[(10 ** 6) * node + i], con)) % con ans %= con #処理内容 def main(): N, M, X = getlist() UF = UnionFind(N) D = defaultdict(int) G = Graph() for i in range(M): x, y, z = getlist() x -= 1; y -= 1 # x, y = list(sorted([x, y])) if not UF.same_check(x, y): UF.union(x, y) G.add_edge(x, y) G.add_edge(y, x) D[(10 ** 6) * x + y] = z D[(10 ** 6) * y + x] = z W = [1] * N visit = [0] * N visit[0] = 1 DFS(N, G, W, visit, 0, D, X) print(ans) if __name__ == '__main__': main()