Submission #66560060
Source Code Expand
Copy
N = int(input())x = list(map(int, input().split()))tree = {}weights = {}for i in range(N-1):a, b, w = map(int, input().split())if a not in tree:tree[a] = set()if b not in tree:tree[b] = set()tree[a].add(b)tree[b].add(a)weights[(a, b)] = wweights[(b, a)] = wcosts = 0while True:t = 0leafs = []for i in range(1,N+1):if len(tree[i]) == 1:l = list(tree[i])[0]
N = int(input()) x = list(map(int, input().split())) tree = {} weights = {} for i in range(N-1): a, b, w = map(int, input().split()) if a not in tree: tree[a] = set() if b not in tree: tree[b] = set() tree[a].add(b) tree[b].add(a) weights[(a, b)] = w weights[(b, a)] = w costs = 0 while True: t = 0 leafs = [] for i in range(1,N+1): if len(tree[i]) == 1: l = list(tree[i])[0] costs += abs(x[i-1]) * weights[(i, l)] x[l-1] += x[i-1] x[i-1] = 0 t += 1 leafs.append((i, l)) for leaf, leaf2 in leafs: if leaf2 in tree and leaf in tree[leaf2]: tree[leaf2].remove(leaf) tree[leaf] = set() if t == 0: break print(costs)
Submission Info
Submission Time | |
---|---|
Task | E - Pair Annihilation |
User | kangping |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 0 |
Code Size | 824 Byte |
Status | TLE |
Exec Time | 2214 ms |
Memory | 154420 KiB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 425 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 56 ms | 76448 KiB |
00_sample_02.txt | AC | 56 ms | 76492 KiB |
00_sample_03.txt | AC | 55 ms | 76484 KiB |
01_test_01.txt | AC | 167 ms | 106136 KiB |
01_test_02.txt | AC | 401 ms | 149176 KiB |
01_test_03.txt | AC | 123 ms | 92028 KiB |
01_test_04.txt | AC | 406 ms | 148432 KiB |
01_test_05.txt | AC | 370 ms | 139640 KiB |
01_test_06.txt | AC | 406 ms | 147812 KiB |
01_test_07.txt | AC | 277 ms | 123004 KiB |
01_test_08.txt | AC | 400 ms | 149492 KiB |
01_test_09.txt | AC | 353 ms | 141284 KiB |
01_test_10.txt | AC | 377 ms | 149272 KiB |
01_test_11.txt | AC | 377 ms | 145848 KiB |
01_test_12.txt | AC | 392 ms | 149600 KiB |
01_test_13.txt | AC | 208 ms | 111912 KiB |
01_test_14.txt | AC | 364 ms | 145884 KiB |
01_test_15.txt | AC | 215 ms | 117612 KiB |
01_test_16.txt | AC | 373 ms | 147848 KiB |
01_test_17.txt | AC | 164 ms | 108340 KiB |
01_test_18.txt | AC | 394 ms | 148244 KiB |
01_test_19.txt | AC | 267 ms | 127824 KiB |
01_test_20.txt | AC | 399 ms | 149240 KiB |
01_test_21.txt | TLE | 2214 ms | 138252 KiB |
01_test_22.txt | TLE | 2214 ms | 142280 KiB |
01_test_23.txt | AC | 230 ms | 154420 KiB |
01_test_24.txt | AC | 228 ms | 153320 KiB |