Submission #13244496


Source Code Expand

Copy
q=range;n,m,k,*p=map(int,open(0).read().split());e=[[]for _ in q(n)]
for i in range(n):
  if p[i]:e[p[i]-1].append(i)
  else:s=i
def bfs(v,t):
  c=[s];d=[0]*n;d[s]=a=1;x=[1]
  if t==s: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:exit(print(-1))
    x,a=bfs(v,j)
    if a<1 or len(x)<w or 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 Python3 (3.4.3)
Score 0
Code Size 592 Byte
Status
Exec Time 2103 ms
Memory 3188 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 30 ms 3064 KB
02.txt 18 ms 3064 KB
03.txt 20 ms 3064 KB
04.txt 30 ms 3064 KB
05.txt 21 ms 3064 KB
06.txt 138 ms 3064 KB
07.txt 63 ms 3064 KB
08.txt 216 ms 3064 KB
09.txt 106 ms 3064 KB
10.txt 1513 ms 3064 KB
11.txt 287 ms 3064 KB
12.txt 865 ms 3064 KB
13.txt 1387 ms 3064 KB
14.txt 1044 ms 3064 KB
15.txt 321 ms 3064 KB
16.txt 1597 ms 3064 KB
17.txt 845 ms 3064 KB
18.txt 2073 ms 3064 KB
19.txt 1553 ms 3064 KB
20.txt 1853 ms 3188 KB
21.txt 645 ms 3064 KB
22.txt 2103 ms 3064 KB
23.txt 2103 ms 3064 KB
24.txt 1718 ms 3064 KB
25.txt 2103 ms 3064 KB
26.txt 1895 ms 3064 KB
27.txt 2023 ms 3064 KB
28.txt 1861 ms 3064 KB
29.txt 2103 ms 3064 KB
30.txt 1848 ms 3064 KB
31.txt 28 ms 3188 KB
32.txt 18 ms 3064 KB
33.txt 21 ms 3064 KB
34.txt 18 ms 3064 KB
35.txt 45 ms 3064 KB
36.txt 59 ms 3064 KB
37.txt 18 ms 3064 KB
38.txt 19 ms 3064 KB
39.txt 18 ms 3064 KB
40.txt 28 ms 3064 KB
s1.txt 18 ms 3064 KB
s2.txt 18 ms 3064 KB