[USACO12DEC]逃跑的BarnRunning Away From- 题目描述 It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to round them all up, and needs your help in the search. FJ's farm is a series of N (1 <= N <= 200,000) pastures nu…
题面 题目描述 给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于等于l的点有多少个. 输入格式: Line 1: 2 integers, N and L (1 <= N <= 200,000, 1 <= L <= 10^18) Lines 2..N: The ith line contains two integers p_i and l_i. p_i (1 <= p_i < i) is the first pasture on the shortest pa…
题面链接 一句话题意:给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于等于l的点有多少个. 我:似乎并不好做啊...看了题解后大雾... sol:考虑树上差分,对于一个点,在他那个位置++,再找到最远的一个点使得该点与当前点的距离小于等于l,在找到的那个点的父亲处--,至于实现倍增好像可以轻松解决. #include <cstdio> using namespace std; #define int long long ; ],re[N],d[N]; signed main() {…
code: #include <cstdio> using namespace std; #define ll long long const int N=200005; int n,fa[N][23],re[N]; ll d[N],up; int main() { //freopen("input.in","r",stdin); int i,j,tmp; scanf("%d%lld",&n,&up); re[1]=1…
题目传送门 逃跑的Barn 题目描述 It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to round them all up, and needs your help in the search. FJ's farm is a series of N (1 <= N <= 200,000) pastures numbered 1...N connected b…
题目描述It's milking time at Farmer John's farm, but the cows have all run away! Farmer John needs to round them all up, and needs your help in the search. FJ's farm is a series of N (1 <= N <= 200,000) pastures numbered 1...N connected by N - 1 bidirec…