output_description: Print the values of the counters on Vertex 1, 2, \ldots, N after all
  operations, in this order, with spaces in between.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N Q
      a_1 b_1
      :
      a_{N-1} b_{N-1}
      p_1 x_1
      :
      p_Q x_Q
attempt: n, k = map(int, input().split())
  p = list(map(int, input().split()))
  c = list(map(int, input().split()))
  s = [[0 for _ in range(2)] for _ in range(n)]
  for i in range(n):
      cnt = 0
      now = i
      while True:
          now = p[now] - 1
          s[i][0] += c[now]
          cnt += 1
          if now == i:
              break
      s[i][1] = cnt
  ans = -(10**16)
  for j in range(n):
      if s[j][0] > 0 and k // s[j][1] > 0:  # 何回か回る
          cnt1, cnt2 = k, k
          a = k // s[j][1]  # 最大周回数
          score1 = a * s[j][0]
          score2 = (a - 1) * s[j][0]
          cnt1 -= a * s[j][1]
          now = j
          pscore1 = 0
          pscore_max1 = 0
          for x in range(cnt1):
              now = p[now] - 1
              pscore1 += c[now]
              pscore_max1 = max(pscore_max1, pscore1)
          score1 += pscore_max1
          now = j
          pscore2 = 0
          pscore_max2 = 0
          for y in range(s[j][1]):
              now = p[now] - 1
              pscore2 += c[now]
              pscore_max2 = max(pscore_max2, pscore2)
          score2 += pscore_max2
          score_max = max(score1, score2)
      else:
          now = j
          score = 0
          score_max = c[p[now] - 1]
          for x in range(min(k, s[j][1])):
              now = p[now] - 1
              score += c[now]
              score_max = max(score_max, score)
      ans = max(ans, score_max)
  print(ans)
  
problem_description: Statement
  
  Given is a rooted tree with N vertices numbered 1 to N. The root is Vertex 1,
  and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.
  
  Each of the vertices has a counter installed. Initially, the counters on all
  the vertices have the value 0.
  
  Now, the following Q operations will be performed:
  
    * Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.
  
  Find the value of the counter on each vertex after all operations.
samples: [{"input": "4 3\n    1 2\n    2 3\n    2 4\n    2 10\n    1 100\n    3 1", "output": "100 110 111 110\n    \n\nThe tree in this input is as follows:\n\n![Figure](https://img.atcoder.jp/ghi/c771b2231be06af79a9994cbe6867552.png)\n\nEach operation changes the values of the counters on the vertices as follows:\n\n  * Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.\n  * Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.\n  * Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.\n\n* * *"}, {"input": "6 2\n    1 2\n    1 3\n    2 4\n    3 6\n    2 5\n    1 10\n    1 10", "output": "20 20 20 20 20 20"}]