結果
問題 | No.1103 Directed Length Sum |
ユーザー | takakin |
提出日時 | 2020-07-31 00:25:42 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 654 bytes |
コンパイル時間 | 966 ms |
コンパイル使用メモリ | 87,180 KB |
実行使用メモリ | 376,916 KB |
最終ジャッジ日時 | 2023-09-18 09:05:38 |
合計ジャッジ時間 | 11,633 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,204 KB |
testcase_01 | AC | 72 ms
71,560 KB |
testcase_02 | AC | 1,027 ms
352,260 KB |
testcase_03 | AC | 864 ms
376,916 KB |
testcase_04 | AC | 2,033 ms
233,940 KB |
testcase_05 | TLE | - |
testcase_06 | AC | 1,108 ms
178,224 KB |
testcase_07 | AC | 269 ms
100,036 KB |
testcase_08 | AC | 394 ms
113,352 KB |
testcase_09 | AC | 187 ms
90,780 KB |
testcase_10 | AC | 549 ms
126,516 KB |
testcase_11 | AC | 1,918 ms
232,816 KB |
testcase_12 | AC | 1,096 ms
178,756 KB |
testcase_13 | AC | 543 ms
128,828 KB |
testcase_14 | AC | 164 ms
88,172 KB |
testcase_15 | AC | 891 ms
156,216 KB |
testcase_16 | AC | 2,124 ms
265,932 KB |
testcase_17 | AC | 2,239 ms
260,892 KB |
testcase_18 | AC | 519 ms
126,476 KB |
testcase_19 | AC | 1,933 ms
252,876 KB |
testcase_20 | AC | 213 ms
94,864 KB |
testcase_21 | AC | 350 ms
109,540 KB |
testcase_22 | AC | 1,552 ms
201,296 KB |
testcase_23 | AC | 891 ms
162,704 KB |
ソースコード
import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) mod=10**9+7 edge=[[] for i in range(n)] edge_r=[[] for i in range(n)] A=[True]*n for i in range(n-1): a,b=map(int,input().split()) edge[a-1].append(b-1) edge_r[b-1].append(a-1) A[b-1]=False for i in range(n): if A[i]: root=i break TS=[root] S=[root] while S: s=S.pop() for g in edge[s]: TS.append(g) S.append(g) ans=0 C=[0]*n for i in range(n)[::-1]: s=TS[i] for g in edge_r[s]: C[g]+=C[s]+1 P=[0]*n for i in range(n): s=TS[i] for g in edge[s]: P[g]+=P[s]+1 for i in range(n): if i!=root: s,g=edge_r[i][0],i ans=(ans+(P[s]+1)*(C[g]+1))%mod print(ans)