P2912 [USACO08OCT]牧场散步Pasture Walking 题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are…
题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are connected by one of N-1 bidirectional…
题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are connected by one of N-1 bidirectional…
http://www.lydsy.com/JudgeOnline/problem.php?id=1602 || https://www.luogu.org/problem/show?pid=2912 题目描述 N头牛(2<=n<=1000)别人被标记为1到n,在同样被标记1到n的n块土地上吃草,第i头牛在第i块牧场吃草. 这n块土地被n-1条边连接. 奶牛可以在边上行走,第i条边连接第Ai,Bi块牧场,第i条边的长度是Li(1<=Li<=10000). 这些边被安排成任意两头奶牛都…
P2912 [USACO08OCT]牧场散步Pasture Walking 求树上两点间路径--->lca 使用倍增处理lca(树剖多长鸭) #include<iostream> #include<cstdio> #include<cstring> #include<cctype> #define re register using namespace std; char gc(){ ],*p1=buf,*p2=buf; ,,stdin),p1==p2…
题面:[USACO08OCT]牧场散步Pasture Walking 题解:LCA模版题 代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; ,max_log=; ][max_log+],edge_head[maxn+],num_edge=,c,Dep[maxn+],u,v,w,A,B; ]; struct Edge{ int to,nx,dis; }edge[(m…
题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are connected by one of N-1 bidirectional…
题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pairs of pastures are connected by one of N-1 bidirectional…
传送门 水题. 直接倍增求lca. x到y的距离为dis[x] + dis[y] - 2 * dis[lca(x, y)] ——代码 #include <cstdio> #include <cstring> #include <iostream> #define MAXN 20002 using namespace std; int n, q, cnt; ], dis[MAXN]; inline void add(int x, int y, int z) { to[cn…
快乐树剖 #include<cstdio> #include<cstring> #include<algorithm> #define rd read() #define lson nd << 1 #define rson nd << 1 | 1 using namespace std; const int N = 1e4; int dep[N], top[N], f[N], son[N], size[N], id[N]; int q, n, h…