题目链接

题意大概是,求有多少三元组$(s,c,f)(s \neq c, c \neq f, s \neq f)$,满足从$s$到$f$有一条简单路径经过$c$。

得到结论:

  1. 点双中任意互不相同的三个点,必定存在一条简单路径依次经过这三个点。
  2. 显然,割点只能经过一次。

建出一棵圆方树,圆点的权值为$-1$,方点的权值为该点双中点的个数,那任意两个圆点之间可以作为它们中转点的个数就是它们在圆方树上路径的点权和。

具体来讲就是割点上只能经过一次,圆点设成$-1$是为了去重方便。

以前只写过点双缩树,这里写圆方树更方便,权且将这道题作为学习的例题吧。

建圆方树只要在Tarjan上稍作修改,这里给出建树的例子:

void Tarjan(int x, int fa) {
    sta[++top] = x; in[x] = -1;
    dfn[x] = low[x] = ++_clock;
    for (int i = las[x]; i; i = pre[i]) {
        if (to[i] == fa) continue;
        if (dfn[to[i]]) {
            low[x] = std::min(low[x], dfn[to[i]]);
        } else {
            Tarjan(to[i], x);
            low[x] = std::min(low[x], low[to[i]]);
            if (dfn[x] <= low[to[i]]) {
                xtr[x].push_back(++c_n); ++in[c_n];
                for (int t = -1; t != to[i]; ) {
                    t = sta[top--];
                    xtr[c_n].push_back(t); ++in[c_n];
                }
            }
        }
    }
}
View Code

相关文章:

  • 2021-05-06
  • 2021-08-05
  • 2021-06-16
  • 2022-01-18
  • 2021-08-16
  • 2022-01-04
  • 2022-02-23
  • 2021-08-30
猜你喜欢
  • 2022-01-19
  • 2021-06-25
  • 2021-06-14
  • 2021-11-13
  • 2022-12-23
  • 2021-06-13
  • 2021-12-12
相关资源
相似解决方案