Submission #30394690


Source Code Expand

import sys
sys.setrecursionlimit(10**7)

N,Q = list(map(int, input().split()))
X = list(map(int, input().split()))
from collections import defaultdict
edges = defaultdict(list)
for i in range(N-1):
    a,b = list(map(int, input().split()))
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

# 挿入 +
mxes = [[] for i in range(N)]
def TFS(u: int, p: int = -1):
    mxes[u].append(X[u])
    for v in edges[u]:
        if v==p: continue
        mxes[u] += TFS(v,u)
    mxes[u] = sorted(mxes[u], reverse=True)[:25]
    return mxes[u]

TFS(0)
#print(mxes)

for i in range(Q):
    v,k = list(map(int, input().split()))
    v -= 1
    k -= 1
    print(mxes[v][k])

Submission Info

Submission Time
Task E - Subtree K-th Max
User fifth_russian
Language Python (3.8.2)
Score 500
Code Size 709 Byte
Status AC
Exec Time 1240 ms
Memory 158832 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 22
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, 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, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 19 ms 9364 KiB
random_01.txt AC 1240 ms 158772 KiB
random_02.txt AC 1186 ms 158832 KiB
random_03.txt AC 1195 ms 158816 KiB
random_04.txt AC 891 ms 41868 KiB
random_05.txt AC 891 ms 42528 KiB
random_06.txt AC 948 ms 42532 KiB
random_07.txt AC 1047 ms 45824 KiB
random_08.txt AC 996 ms 45988 KiB
random_09.txt AC 1032 ms 46016 KiB
random_10.txt AC 958 ms 44512 KiB
random_11.txt AC 946 ms 44728 KiB
random_12.txt AC 967 ms 44628 KiB
random_13.txt AC 985 ms 45548 KiB
random_14.txt AC 989 ms 45376 KiB
random_15.txt AC 1003 ms 45416 KiB
random_16.txt AC 1000 ms 45436 KiB
random_17.txt AC 993 ms 45420 KiB
random_18.txt AC 1008 ms 45496 KiB
sample_01.txt AC 26 ms 9344 KiB
sample_02.txt AC 23 ms 9252 KiB
sample_03.txt AC 20 ms 9256 KiB