結果
問題 | No.1843 Tree ANDistance |
ユーザー | mkawa2 |
提出日時 | 2023-02-16 10:45:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 989 ms / 2,000 ms |
コード長 | 1,469 bytes |
コンパイル時間 | 120 ms |
コンパイル使用メモリ | 82,364 KB |
実行使用メモリ | 143,156 KB |
最終ジャッジ日時 | 2024-07-18 12:37:10 |
合計ジャッジ時間 | 20,775 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 962 ms
140,604 KB |
testcase_01 | AC | 984 ms
140,736 KB |
testcase_02 | AC | 978 ms
140,632 KB |
testcase_03 | AC | 952 ms
140,396 KB |
testcase_04 | AC | 989 ms
140,264 KB |
testcase_05 | AC | 655 ms
139,416 KB |
testcase_06 | AC | 780 ms
143,156 KB |
testcase_07 | AC | 920 ms
137,344 KB |
testcase_08 | AC | 937 ms
139,192 KB |
testcase_09 | AC | 902 ms
138,428 KB |
testcase_10 | AC | 863 ms
137,804 KB |
testcase_11 | AC | 953 ms
139,328 KB |
testcase_12 | AC | 593 ms
137,836 KB |
testcase_13 | AC | 726 ms
135,128 KB |
testcase_14 | AC | 90 ms
77,524 KB |
testcase_15 | AC | 98 ms
78,180 KB |
testcase_16 | AC | 66 ms
75,336 KB |
testcase_17 | AC | 80 ms
75,264 KB |
testcase_18 | AC | 53 ms
64,896 KB |
testcase_19 | AC | 91 ms
78,336 KB |
testcase_20 | AC | 83 ms
77,440 KB |
testcase_21 | AC | 36 ms
52,352 KB |
testcase_22 | AC | 35 ms
52,352 KB |
testcase_23 | AC | 35 ms
52,480 KB |
testcase_24 | AC | 34 ms
52,352 KB |
testcase_25 | AC | 34 ms
52,480 KB |
testcase_26 | AC | 39 ms
52,480 KB |
testcase_27 | AC | 37 ms
52,480 KB |
testcase_28 | AC | 695 ms
122,124 KB |
testcase_29 | AC | 481 ms
110,560 KB |
testcase_30 | AC | 453 ms
110,608 KB |
testcase_31 | AC | 723 ms
128,288 KB |
testcase_32 | AC | 692 ms
122,516 KB |
testcase_33 | AC | 188 ms
96,376 KB |
testcase_34 | AC | 453 ms
118,584 KB |
testcase_35 | AC | 33 ms
53,548 KB |
testcase_36 | AC | 32 ms
52,900 KB |
testcase_37 | AC | 32 ms
53,004 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) 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 = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 n = II() to = [[] for _ in range(n)] cc = {} for _ in range(n-1): u, v, c = LI1() c += 1 to[u].append(v) to[v].append(u) cc[u, v] = cc[v, u] = c parent, depth, vis = [-1]*n, [0]*n, [0]*n def dfs(root=0): uu, stack = [], [root] vis[root] = 1 while stack: u = stack.pop() uu.append(u) for v in to[u]: if vis[v]: continue vis[v] = 1 parent[v] = u stack.append(v) return uu uu = dfs() ans = 0 for i in range(30)[::-1]: cnt = [1]*n s = 0 for u in uu[:0:-1]: p = parent[u] if cc[p, u] >> i & 1: s += cnt[p]*cnt[u] cnt[p] += cnt[u] ans += pow(2, i, md)*s%md ans %= md print(ans)