Submission #19218163


Source Code Expand

Copy
from sys import stdin 
def input():
    return stdin.readline()

n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(1,n):
    p = int(input())
    g[p].append(i)
val = [0 for i in range(n+1)]
for i in range(m):
    b,c = map(int,input().split())
    val[b] = c
for i in range(n):
    q = []
    for j in g[0]:
        q.append(j)
    while q:
        idx = q.pop()
        if g[idx]:
            temp = 2**63 
            for j in g[idx]:
                if val[j]<temp:
                    temp = val[j]
            val[idx] += temp 
            #print(idx,temp)
            for j in g[idx]:
                val[j] -= temp
                q.append(j)
print(sum(val))
#print(g)

Submission Info

Submission Time
Task B - PackDrop
User umacoder
Language PyPy3 (7.3.0)
Score 300
Code Size 729 Byte
Status AC
Exec Time 115 ms
Memory 68964 KB

Judge Result

Set Name All
Score / Max Score 300 / 300
Status
AC × 27
Set Name Test Cases
All 00_sample_1, 00_sample_2, 00_sample_3, 10_random_00_n_5, 10_random_01_n_10, 10_random_02_n_2, 10_random_03_n_7, 10_random_04_n_6, 20_random_00_n_64, 20_random_01_n_95, 20_random_02_n_20, 20_random_03_n_33, 20_random_04_n_91, 30_random_00_n_793, 30_random_01_n_611, 30_random_02_n_852, 40_random_00_n_1000, 40_random_01_n_1000, 50_edge_one_00_n_11, 50_edge_one_01_n_101, 50_edge_one_02_n_999, 98_almost_straight_00_n_1000, 98_almost_straight_01_n_1000, 98_almost_straight_02_n_1000, 99_straight_00_n_10, 99_straight_01_n_100, 99_straight_02_n_1000
Case Name Status Exec Time Memory
00_sample_1 AC 68 ms 61968 KB
00_sample_2 AC 58 ms 61860 KB
00_sample_3 AC 55 ms 62064 KB
10_random_00_n_5 AC 56 ms 61800 KB
10_random_01_n_10 AC 56 ms 62176 KB
10_random_02_n_2 AC 58 ms 61876 KB
10_random_03_n_7 AC 55 ms 62148 KB
10_random_04_n_6 AC 59 ms 62140 KB
20_random_00_n_64 AC 72 ms 68140 KB
20_random_01_n_95 AC 77 ms 68172 KB
20_random_02_n_20 AC 59 ms 62184 KB
20_random_03_n_33 AC 62 ms 64108 KB
20_random_04_n_91 AC 76 ms 68340 KB
30_random_00_n_793 AC 100 ms 68064 KB
30_random_01_n_611 AC 96 ms 68556 KB
30_random_02_n_852 AC 104 ms 68100 KB
40_random_00_n_1000 AC 112 ms 68624 KB
40_random_01_n_1000 AC 115 ms 68668 KB
50_edge_one_00_n_11 AC 58 ms 62200 KB
50_edge_one_01_n_101 AC 70 ms 68296 KB
50_edge_one_02_n_999 AC 110 ms 68424 KB
98_almost_straight_00_n_1000 AC 94 ms 68456 KB
98_almost_straight_01_n_1000 AC 94 ms 68964 KB
98_almost_straight_02_n_1000 AC 97 ms 68960 KB
99_straight_00_n_10 AC 54 ms 61968 KB
99_straight_01_n_100 AC 67 ms 68228 KB
99_straight_02_n_1000 AC 91 ms 68144 KB