-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAboris.java
More file actions
42 lines (42 loc) · 916 Bytes
/
Aboris.java
File metadata and controls
42 lines (42 loc) · 916 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
34
35
36
37
38
39
40
41
42
import java.util.*;
import java.util.LinkedList;
class Arboris
{
static class Node
{
int v;
Node l,r;
Node(int v)
{
this.v=v;
}
}
static Node build(String a[])
{
if(a[0].equals("null"))
return null;
Node r=new Node(Integer.parseInt(a[0]));
Queue<Node> q=new LinkedList<>();
q.add(r);
for(int i=1;!q.isEmpty()&&i<a.length;i++)
{
Node n=q.poll();
if(!a[i].equals("null"))
q.add(n.l=new Node(Integer.parseInt(a[i])));
if(++i<a.length && !a[i].equals("null"))
q.add(n.r=new Node(Integer.parseInt(a[i])));
}
return r;
}
static int d(Node n)
{
if(n==null)
return 0;
return 1+Math.max(d(n.l),d(n.r));
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println(d(build(in.nextLine().split(" "))));
}
}