import
java.util.*;
@SuppressWarnings
(
"unchecked"
)
public
class
GFG{
static
class
pair
{
int
first, second;
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
final
int
N =
100005
;
static
ArrayList ans;
static
ArrayList flag;
static
void
minimumTime(
int
u,
int
par,
ArrayList hasApple,
ArrayList adj[])
{
if
((
boolean
)hasApple.get(u) ==
true
)
flag.set(u,
1
);
for
(
int
it : (ArrayList<Integer>)adj[u])
{
if
(it != par)
{
minimumTime(it, u, hasApple, adj);
if
((
int
)flag.get(it) >
0
)
ans.set(u, (
int
)ans.get(u) +
(
int
)ans.get(it) +
2
);
flag.set(u, (
int
)flag.get(u) |
(
int
)flag.get(it));
}
}
}
public
static
void
main(String []args)
{
int
n =
7
;
ans =
new
ArrayList();
flag =
new
ArrayList();
for
(
int
i =
0
; i < N; i++)
{
ans.add(
0
);
flag.add(
0
);
}
ArrayList hasApple =
new
ArrayList();
hasApple.add(
false
);
hasApple.add(
false
);
hasApple.add(
true
);
hasApple.add(
false
);
hasApple.add(
true
);
hasApple.add(
true
);
hasApple.add(
false
);
ArrayList edges =
new
ArrayList();
edges.add(
new
pair(
0
,
1
));
edges.add(
new
pair(
0
,
2
));
edges.add(
new
pair(
1
,
4
));
edges.add(
new
pair(
1
,
5
));
edges.add(
new
pair(
2
,
3
));
edges.add(
new
pair(
2
,
6
));
ArrayList []adj =
new
ArrayList[n];
for
(
int
i =
0
; i < n; i++)
{
adj[i] =
new
ArrayList();
}
for
(
int
i =
0
; i < edges.size(); i++)
{
int
source_node = ((pair)edges.get(i)).first;
int
destination_node = ((pair)edges.get(i)).second;
adj[source_node].add(destination_node);
adj[destination_node].add(source_node);
}
minimumTime(
0
, -
1
, hasApple, adj);
System.out.print(ans.get(
0
));
}
}