Submission #13244708


Source Code Expand

Copy
q=range;n,m,k,*p=map(int,open(0).read().split());e=[[]for _ in q(n)]
for i in q(n):
  if p[i]:e[p[i]-1].append(i)
  else:r=i
def b(v,t):
  c=[r];d=[0]*n;d[r]=1;x=[1];a=-1
  if t==r:return[[],1]
  for i in c:
    for j in e[i]:
      if j==t:a=d[i]+1;continue
      if j not in v:c.append(j);d[j]=d[i]+1;x.append(d[j])
  return[sorted(x),a]
v=set();z=[]
for i in q(m):
  w=m-i-1
  for j in q(n+1):
    if j==n:z=[-1]
    x,a=b(v,j)
    if(a<1)|(len(x)<w)|(j in v):continue
    if sum(x[:w])<=k-a<=sum(x[::-1][:w]):k-=a;z.append(j+1);v.add(j);break
print(*z)

Submission Info

Submission Time
Task F - Coins on the tree
User tyawanmusi
Language PyPy3 (2.4.0)
Score 0
Code Size 576 Byte
Status
Exec Time 601 ms
Memory 48604 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt
All 0 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt 224 ms 42736 KB
02.txt 168 ms 38384 KB
03.txt 177 ms 39408 KB
04.txt 204 ms 41840 KB
05.txt 178 ms 39664 KB
06.txt 235 ms 43740 KB
07.txt 226 ms 43372 KB
08.txt 270 ms 45532 KB
09.txt 247 ms 43996 KB
10.txt 477 ms 46812 KB
11.txt 285 ms 45656 KB
12.txt 366 ms 45404 KB
13.txt 450 ms 45404 KB
14.txt 386 ms 45788 KB
15.txt 271 ms 44124 KB
16.txt 482 ms 45916 KB
17.txt 336 ms 45148 KB
18.txt 592 ms 48220 KB
19.txt 479 ms 45788 KB
20.txt 561 ms 48604 KB
21.txt 360 ms 44764 KB
22.txt 601 ms 46044 KB
23.txt 592 ms 46044 KB
24.txt 585 ms 46172 KB
25.txt 587 ms 46428 KB
26.txt 531 ms 46812 KB
27.txt 580 ms 48472 KB
28.txt 540 ms 46424 KB
29.txt 571 ms 48348 KB
30.txt 502 ms 45276 KB
31.txt 218 ms 42608 KB
32.txt 194 ms 40304 KB
33.txt 229 ms 44144 KB
34.txt 188 ms 40816 KB
35.txt 275 ms 46556 KB
36.txt 197 ms 40816 KB
37.txt 165 ms 38768 KB
38.txt 165 ms 38640 KB
39.txt 174 ms 39280 KB
40.txt 175 ms 39280 KB
s1.txt 158 ms 38256 KB
s2.txt 160 ms 38256 KB