結果
問題 | No.1103 Directed Length Sum |
ユーザー | tonnnura172 |
提出日時 | 2020-07-11 05:07:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,592 ms / 3,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 769 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 270,892 KB |
最終ジャッジ日時 | 2024-10-12 06:46:48 |
合計ジャッジ時間 | 15,284 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
67,168 KB |
testcase_01 | AC | 59 ms
67,468 KB |
testcase_02 | AC | 665 ms
263,580 KB |
testcase_03 | AC | 587 ms
270,892 KB |
testcase_04 | AC | 915 ms
166,464 KB |
testcase_05 | AC | 1,592 ms
243,656 KB |
testcase_06 | AC | 577 ms
136,948 KB |
testcase_07 | AC | 163 ms
94,040 KB |
testcase_08 | AC | 214 ms
103,100 KB |
testcase_09 | AC | 128 ms
87,140 KB |
testcase_10 | AC | 303 ms
111,408 KB |
testcase_11 | AC | 1,022 ms
184,708 KB |
testcase_12 | AC | 576 ms
137,292 KB |
testcase_13 | AC | 305 ms
113,548 KB |
testcase_14 | AC | 115 ms
85,300 KB |
testcase_15 | AC | 503 ms
128,180 KB |
testcase_16 | AC | 1,100 ms
191,340 KB |
testcase_17 | AC | 1,152 ms
194,916 KB |
testcase_18 | AC | 289 ms
111,108 KB |
testcase_19 | AC | 1,041 ms
196,344 KB |
testcase_20 | AC | 134 ms
89,700 KB |
testcase_21 | AC | 203 ms
98,148 KB |
testcase_22 | AC | 812 ms
173,108 KB |
testcase_23 | AC | 502 ms
136,160 KB |
ソースコード
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2 from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul, add from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N = INT() tree = [[] for _ in range(N)] din = [0]*N for _ in range(N-1): A, B = MAP() tree[A-1].append(B-1) din[B-1] += 1 root = din.index(0) size_d = [0]*N size_u = [0]*N parent = [0]*N order = [] stack = [root] while stack: x = stack.pop() size_u[x] += 1 order.append(x) for y in tree[x]: size_u[y] += size_u[x] parent[y] = x stack.append(y) ans = 0 for v in order[::-1]: # 根に遠いほうから(down方向のボトムアップ) size_d[v] += 1 if v == root: break p = parent[v] s = size_d[v] ans += s * size_u[p] ans %= mod size_d[p] += s print(ans)