結果

問題 No.1103 Directed Length Sum
ユーザー tikitaka1201tikitaka1201
提出日時 2020-07-09 21:53:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 468 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 274,832 KB
最終ジャッジ日時 2024-04-17 02:02:04
合計ジャッジ時間 18,051 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
51,840 KB
testcase_01 AC 42 ms
51,968 KB
testcase_02 WA -
testcase_03 AC 817 ms
274,832 KB
testcase_04 AC 1,112 ms
129,280 KB
testcase_05 AC 1,902 ms
165,376 KB
testcase_06 AC 685 ms
111,232 KB
testcase_07 AC 204 ms
84,224 KB
testcase_08 AC 285 ms
88,960 KB
testcase_09 AC 161 ms
80,896 KB
testcase_10 AC 367 ms
93,184 KB
testcase_11 AC 1,112 ms
134,016 KB
testcase_12 AC 684 ms
110,848 KB
testcase_13 AC 373 ms
94,336 KB
testcase_14 AC 144 ms
80,256 KB
testcase_15 AC 549 ms
103,296 KB
testcase_16 AC 1,271 ms
140,928 KB
testcase_17 AC 1,360 ms
143,488 KB
testcase_18 AC 351 ms
93,312 KB
testcase_19 AC 1,200 ms
135,552 KB
testcase_20 AC 180 ms
82,688 KB
testcase_21 AC 270 ms
87,936 KB
testcase_22 AC 953 ms
124,800 KB
testcase_23 AC 571 ms
105,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
mod=10**9+7
es=[[] for _ in range(n)]
par=[0]*n
for _ in range(n-1):
    a,b=map(int,input().split())
    es[a-1].append(b-1)
    par[b-1]=1

for i in range(n):
    if par[i]==0:
        root=i
        break
stack=[(root,0)]
ans=0
visited=[0]*n
while stack:
    now,depth=stack.pop()
    ans+=(depth*(depth+1))%mod//2
    ans%=mod
    if visited[now]==0:
        visited[now]=1
        for e in es[now]:
            stack.append((e, depth+1))
print(ans)
0