P r o b l e m \mathrm{Problem} Problem
S o l u t i o n \mathrm{Solution} Solution
首先不难发现一个结论:
- 若两条路径相交,则一条路径的LCA一定在另一条路径上。
根据图像,我们能得到另一个结论: - 两条路径中,深度较大的LCA一定在另一条路径上。
因此我们可以将LCA排序,每一次统计路径上有多少LCA加入即可。统计完以后,把当前路径的LCA也加入。
C o d e \mathrm{Code} Code
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, m, cnt(0);
int L[N], R[N], fa[N];
int size[N], dep[N], son[N], top[N];
vector < int > a[N];
struct node {
int u, v, lca; } A[N * 10];
int read(void)
{
int s = 0, w = 0; char c = getchar();
while (c < '0' || c > '9') w |= c ==