結果
問題 | No.1488 Max Score of the Tree |
ユーザー | ygd. |
提出日時 | 2021-04-23 22:26:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,842 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 76,768 KB |
最終ジャッジ日時 | 2024-07-04 08:17:24 |
合計ジャッジ時間 | 3,233 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 64 ms
70,400 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 38 ms
52,888 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 69 ms
73,300 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 37 ms
54,056 KB |
testcase_24 | AC | 36 ms
53,084 KB |
testcase_25 | AC | 43 ms
59,768 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
ソースコード
N,K = map(int,input().split()) G = [[] for _ in range(N)] RN = [[-1]*N for _ in range(N)] for i in range(N-1): a,b,c = map(int,input().split()) a-=1;b-=1 #0-index G[a].append((b,c,i)) #相手、cost, index G[b].append((a,c,i)) RN[a][b] = (i,c) RN[b][a] = (i,c) #print(RN) leaf = [0]*N par = [-1]*N stack = [] stack.append(~0) stack.append(0) while stack: v = stack.pop() if v >= 0: for u,cost,idx in G[v]: if u == par[v]: continue par[u] = v stack.append(~u) stack.append(u) else: a = ~v if a == 0: continue if len(G[a]) == 1: leaf[a] = 1 leaf[par[a]] += 1 else: #print(a,par[a],"L",leaf[a]) leaf[par[a]] += leaf[a] #print(par) #print(leaf) ans = 0 for i in range(N): npar = [-1]*N stack = [i] while stack: v = stack.pop() for u,cost,idx in G[v]: if u == npar[v]: continue npar[u] = v stack.append(u) #print(i,npar) for j in range(i+1,N): cum = 0 nj = j used = [0]*(N-1) Flag = 0 while npar[nj] != -1: nxt = npar[nj] idx, cost = RN[nj][nxt] used[idx] = 1 cum += cost nj = nxt if cum > K: Flag = 1 break if Flag == 1: continue ret = 0 stack = [0] while stack: v = stack.pop() for u,cost,idx in G[v]: if u == par[v]: continue if used[idx] == 1: ret += cost*leaf[u]*2 else: ret += cost*leaf[u] stack.append(u) #print(i,j,ret,used) ans = max(ans,ret) print(ans)