随笔分类 - LCA
摘要:传送门 总算是做上一道LCA的应用题了... 题意:有$n$个牧场, $m$根管道分别连接编号为$u,v$的牧场花费$p_{i}$,在第$i$个牧场挖口井需要花费$w_{i}$,有$P$根管道直接连通着$u,v$,即免费连上$u,v$ 对每根免费管道输出让所有牧场都有水的最小花费 先是最小生成树,用
阅读全文
摘要:传送门 没啥好说的。就是一个LCA。 不过就是有从根到子树里任意一个节点只需要一次操作,特判一下LCA是不是等于v。相等的话不用走。否则就是1次操作。 主要是想写一下倍增的板子。 倍增基于二进制。暴力求LCA算法是while循环一步一步往上走。但其实是不需要的。 因为一个点走到它的任意一个祖先都是确
阅读全文
摘要:传送门 三个点之间的最短路径 答案就是两两lca之和除以2 注意输出格式。 #include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (
阅读全文
摘要:传送门 继续水板子题... #include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') {
阅读全文
摘要:传送门 继续水板子题... #include <bits/stdc++.h> #define ll long long using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch
阅读全文
摘要:传送门 继续水板子题... #include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') {
阅读全文
摘要:过了这么长的时间终于开始看LCA了... 有一次训练题卡在LCA当时不会...拖了好久好久...其实现在还是不会... 只会tarjan... 传送门 板子题咯 tarjan的算法就是基于先序遍历的顺序的 #include <bits/stdc++.h> using namespace std; i
阅读全文

浙公网安备 33010602011771号