提出 #18047488


ソースコード 拡げる

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(readline())
n,Q = map(int,readline().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,readline().split())
    g[a-1].append((b-1,i))
    g[b-1].append((a-1,i))

eid = [-1]*n 
order = []
st = [0]
parent = [-1]*n
while st:
    v = st.pop()
    order.append(v)
    for c,i in g[v]:
        if c != parent[v]:
            st.append(c)
            eid[c] = i
            parent[c] = v

q = [[] for _ in range(n)]
for t in range(Q):
    u,v,c = map(int,readline().split())
    q[u-1].append((t,c))
    q[v-1].append((t,c))

from heapq import *
col = [0]*(n-1)
dp = [[] for _ in range(n)]
for i in order[n-1:0:-1]:
    for t,c in q[i]:
        heappush(dp[i],(-t,c))
    while dp[i]:
        a = heappop(dp[i])
        if dp[i] and dp[i][0][0] == a[0]:
            heappop(dp[i])
        else:
            heappush(dp[i],a)
            break
    if dp[i]:
        col[eid[i]] = dp[i][0][1]
    
    p = parent[i]
    if len(dp[i]) > len(dp[p]):
        dp[i],dp[p] = dp[p],dp[i]
    for a in dp[i]:
        heappush(dp[p],a)

print(*col,sep="\n")

提出情報

提出日時
問題 M - 筆塗り
ユーザ convexineq
言語 PyPy3 (7.3.0)
得点 6
コード長 1227 Byte
結果 AC
実行時間 819 ms
メモリ 143948 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 6 / 6
結果
AC × 2
AC × 32
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 72 ms 62544 KiB
random_02.txt AC 814 ms 143948 KiB
random_03.txt AC 473 ms 109180 KiB
random_04.txt AC 238 ms 77508 KiB
random_05.txt AC 358 ms 93192 KiB
random_06.txt AC 95 ms 71676 KiB
random_07.txt AC 450 ms 112040 KiB
random_08.txt AC 322 ms 92292 KiB
random_09.txt AC 660 ms 119700 KiB
random_10.txt AC 469 ms 107216 KiB
random_11.txt AC 53 ms 62732 KiB
random_12.txt AC 819 ms 142216 KiB
random_13.txt AC 396 ms 104648 KiB
random_14.txt AC 652 ms 132528 KiB
random_15.txt AC 549 ms 116640 KiB
random_16.txt AC 246 ms 99752 KiB
random_17.txt AC 544 ms 126288 KiB
random_18.txt AC 219 ms 83516 KiB
random_19.txt AC 469 ms 114996 KiB
random_20.txt AC 223 ms 88668 KiB
random_21.txt AC 130 ms 76648 KiB
random_22.txt AC 289 ms 99384 KiB
random_23.txt AC 276 ms 84636 KiB
random_24.txt AC 276 ms 86524 KiB
random_25.txt AC 329 ms 91120 KiB
random_26.txt AC 131 ms 83660 KiB
random_27.txt AC 432 ms 108460 KiB
random_28.txt AC 506 ms 119860 KiB
random_29.txt AC 337 ms 109868 KiB
random_30.txt AC 361 ms 108276 KiB
sample_01.txt AC 52 ms 62712 KiB
sample_02.txt AC 54 ms 62716 KiB