結果
問題 | No.1002 Twotone |
ユーザー |
![]() |
提出日時 | 2025-02-28 01:50:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,028 bytes |
コンパイル時間 | 458 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 316,364 KB |
最終ジャッジ日時 | 2025-02-28 01:50:27 |
合計ジャッジ時間 | 16,649 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | WA * 5 TLE * 2 -- * 26 |
ソースコード
import sys input=sys.stdin.buffer.readline n,K=map(int,input().split()) e=[[] for i in range(n)] for _ in range(n-1): a,b,c=map(int,input().split()) a-=1 b-=1 c-=1 e[a]+=[(b,c)] e[b]+=[(a,c)] def CD(e): c=[] p=[-1]*n d=[0]*n v=[0]*n u=[0]*n sq=[(0,n)] o=[] for start,W in sq: q=[start] d[start]=0 while len(q)>0: s=q[-1] if v[s]==0: v[s]=1 o+=[s] for t,_ in e[s]: if v[t]==0 and p[t]==-1: q+=[t] d[t]=d[s]+1 else: u[s]=1+sum(u[t] for t,_ in e[s] if v[t]==0 and p[t]==-1) for t,_ in e[s]: f=1 if p[t]==-1: if d[t]>d[s]: f&=W-u[t]>=u[t] else: f&=u[s]>=W-u[s] if f: nc=s v[s]=0 q.pop() p[nc]=len(c) c+=[nc] for t,_ in e[nc]: if p[t]==-1: if d[t]>d[nc]: sq+=[(t,u[t])] else: sq+=[(t,W-u[nc])] o.clear() return c,p cdc,cdp=CD(e)