-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1068(Tree).java
More file actions
33 lines (26 loc) · 869 Bytes
/
1068(Tree).java
File metadata and controls
33 lines (26 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int N;
static ArrayList<Integer>arrayList[];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int root = -1;
N = Integer.parseInt(br.readLine());
arrayList = new ArrayList[N];
for(int i = 0; i < N; i++){
arrayList[i] = new ArrayList<>();
}
StringTokenizer st = new StringTokenizer(br.readLine()," ");
for(int i = 0; i<N; i++){
int num = Integer.parseInt(st.nextToken());
if(num == -1){
root = i;
}else{
arrayList[num].add(i);
}
}
int delete = Integer.parseInt(br.readLine());
}
}