PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000014. Đếm đỉnh cách đúng K cạnh (Complete Binary Tree)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đỉnh cách đúng K cạnh (Complete Binary Tree)
Complete Binary Tree
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Consider a binary tree indexed as an array. The root is vertex ; vertex has children and whenever those indices do not exceed . Exactly vertices exist.
The distance between two vertices is the number of edges on the unique path between them. Given vertex and integer , count vertices for which .
The source problem uses multiple test cases. This version accepts one set of parameters .
Input
- The only line contains three integers .
Output
Print the number of vertices at distance exactly from .
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
10 2 2
Output
4
Explanation
In the tree on indices through , vertices at distance two from vertex are , so the answer is .