Submission #4659991
Source Code Expand
import sys sys.setrecursionlimit(10**6) N,M,K=map(int,input().split()) Graph=[int(i)-1 for i in input().split()] Tree=[[] for i in range(N)] for i,p in enumerate(Graph): if p!=-1: Tree[p].append(i) else: root=i depth=[0]*N count=[0]*N size=[0]*N def dfs_depth(x,d): depth[x]=d for y in Tree[x]: dfs_depth(y,d+1) def dfs(x): S,C=1,depth[x]+1 for y in Tree[x]: s,c=dfs(y) S+=s C+=c size[x],count[x]=S,C return (S,C) dfs_depth(root,0) dfs(root) def check(x,k,m): if size[x]==0: return False if depth[x]+1>k or (depth[x]+1)+(count[root]-count[x])<k: return False if 1+(size[root]-size[x])<m: return False return True ans=[] k_,m_,flag=0,0,False for i in range(M): for p in range(N): if check(p,K-k_,M-m_): ans.append(str(p+1)) flag=True break if not flag: print(-1) exit() else: k_+=depth[p]+1 m_+=1 if p!=root: Tree[Graph[p]].remove(p) count,size=[0]*N,[0]*N dfs(root) flag=False print(" ".join(ans))
Submission Info
Submission Time | |
---|---|
Task | F - Coins on the tree |
User | Chanyuh |
Language | PyPy3 (2.4.0) |
Score | 0 |
Code Size | 1089 Byte |
Status | WA |
Exec Time | 361 ms |
Memory | 57560 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 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 | AC | 175 ms | 38768 KB |
02.txt | WA | 171 ms | 38256 KB |
03.txt | WA | 172 ms | 38256 KB |
04.txt | WA | 188 ms | 40560 KB |
05.txt | WA | 168 ms | 38256 KB |
06.txt | WA | 202 ms | 42076 KB |
07.txt | WA | 214 ms | 42992 KB |
08.txt | WA | 252 ms | 47196 KB |
09.txt | WA | 215 ms | 43504 KB |
10.txt | WA | 251 ms | 46812 KB |
11.txt | WA | 204 ms | 42076 KB |
12.txt | WA | 222 ms | 43996 KB |
13.txt | WA | 274 ms | 48476 KB |
14.txt | WA | 226 ms | 44252 KB |
15.txt | WA | 199 ms | 41456 KB |
16.txt | WA | 256 ms | 46940 KB |
17.txt | WA | 242 ms | 45276 KB |
18.txt | WA | 315 ms | 52700 KB |
19.txt | WA | 283 ms | 49244 KB |
20.txt | WA | 297 ms | 50652 KB |
21.txt | WA | 278 ms | 48988 KB |
22.txt | WA | 354 ms | 56408 KB |
23.txt | WA | 361 ms | 57560 KB |
24.txt | WA | 321 ms | 52060 KB |
25.txt | WA | 305 ms | 51420 KB |
26.txt | WA | 268 ms | 47580 KB |
27.txt | WA | 296 ms | 50140 KB |
28.txt | WA | 327 ms | 52444 KB |
29.txt | WA | 339 ms | 54748 KB |
30.txt | WA | 281 ms | 48732 KB |
31.txt | AC | 178 ms | 39280 KB |
32.txt | WA | 172 ms | 38384 KB |
33.txt | AC | 168 ms | 38256 KB |
34.txt | WA | 167 ms | 38256 KB |
35.txt | AC | 177 ms | 39280 KB |
36.txt | WA | 173 ms | 38768 KB |
37.txt | WA | 167 ms | 38256 KB |
38.txt | WA | 169 ms | 38256 KB |
39.txt | AC | 168 ms | 38384 KB |
40.txt | WA | 174 ms | 38384 KB |
s1.txt | AC | 177 ms | 38256 KB |
s2.txt | WA | 170 ms | 38256 KB |