結果
問題 |
No.2638 Initial fare
|
ユーザー |
![]() |
提出日時 | 2024-02-19 21:36:16 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 576 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 82,988 KB |
実行使用メモリ | 517,180 KB |
最終ジャッジ日時 | 2024-09-29 01:32:16 |
合計ジャッジ時間 | 14,281 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 MLE * 1 |
ソースコード
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)