Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Distribute Coins in Binary Tree
Bookmark
Input
Example 1
Example 2
Example 3
Custom
tree
=
[3, 0, 0]
3
0
0
moves
0
moves = coins crossing every edge = Σ |subtree excess|
3
0
0
moves
0
moves = coins crossing every edge = Σ |subtree excess|
3
0
0
moves
0
dfs(
3
coins)
3
0
0
moves
0
dfs(
0
coins)
3
0
0
moves
0
moves += |
0
| + |
0
| =
0
→
0
1
3
0
0
-1
moves
0
request
1
from the parent
1
3
0
0
-1
moves
0
dfs(
0
coins)
1
3
0
0
-1
moves
0
right is null: excess
0
1
1
3
0
0
-1
-1
moves
0
request
1
from the parent
1
1
3
0
0
0
-1
-1
moves
2
excess =
3
+ (0) + (-1) - 1 =
0
1
1
3
0
0
0
-1
-1
moves
2
2 moves
algo
master
.
io
Step:
Start: move coins until every node holds exactly 1
0 / 20
Input
Example 1
Example 2
Example 3
Custom
tree
=
[3, 0, 0]
0 / 20
algo
master
.
io
Step:
Start: move coins until every node holds exactly 1