結果

問題 No.2638 Initial fare
ユーザー こめだわらこめだわら
提出日時 2024-02-19 21:37:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 576 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 114,048 KB
最終ジャッジ日時 2024-04-23 16:17:43
合計ジャッジ時間 29,588 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 36 ms
10,752 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 31 ms
10,752 KB
testcase_04 AC 1,303 ms
44,032 KB
testcase_05 AC 1,342 ms
45,824 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 1,292 ms
45,440 KB
testcase_08 AC 1,118 ms
43,776 KB
testcase_09 AC 1,222 ms
46,592 KB
testcase_10 AC 1,232 ms
46,720 KB
testcase_11 AC 29 ms
10,880 KB
testcase_12 AC 1,302 ms
45,012 KB
testcase_13 AC 1,070 ms
42,100 KB
testcase_14 AC 1,227 ms
46,456 KB
testcase_15 AC 1,224 ms
47,064 KB
testcase_16 AC 31 ms
10,880 KB
testcase_17 AC 1,267 ms
45,696 KB
testcase_18 AC 1,202 ms
45,184 KB
testcase_19 AC 1,408 ms
55,296 KB
testcase_20 AC 1,309 ms
49,792 KB
testcase_21 AC 1,458 ms
60,032 KB
testcase_22 AC 30 ms
10,880 KB
testcase_23 AC 1,903 ms
114,048 KB
testcase_24 TLE -
testcase_25 AC 30 ms
10,880 KB
testcase_26 AC 1,713 ms
85,632 KB
testcase_27 AC 1,910 ms
104,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(500000)

N=int(input())
edge=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    edge[a].append(b)
    edge[b].append(a)

used=[0]*N
total=0
def dfs(i):
    global total
    used[i]=1
    dp=[0,0,0]
    c=[0,0,0]
    for np in edge[i]:
        if used[np]==1:
            continue
        d=dfs(np)
        total+=d[0]*c[0]+d[0]*c[1]+d[1]*c[0]
        for j in range(3):
            c[j]+=d[j]
    total+=c[0]+c[1]+c[2]
    dp[0]=1
    dp[1]=c[0]
    dp[2]=c[1]
    return dp

dfs(0)
print(total)
0