結果
| 問題 |
No.1002 Twotone
|
| コンテスト | |
| ユーザー |
sasa8uyauya
|
| 提出日時 | 2025-02-28 02:25:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 992 bytes |
| コンパイル時間 | 421 ms |
| コンパイル使用メモリ | 82,276 KB |
| 実行使用メモリ | 190,444 KB |
| 最終ジャッジ日時 | 2025-02-28 02:26:26 |
| 合計ジャッジ時間 | 23,111 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | WA * 12 TLE * 6 -- * 15 |
ソースコード
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)]
for start,W in sq:
q=[start]
d[start]=0
while len(q)>0:
s=q[-1]
if v[s]==0:
v[s]=1
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])]
return c,p
cdc,cdp=CD(e)
sasa8uyauya