BZOJ1123或洛谷3469 [POI2008]BLO-Blockade】的更多相关文章

BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关的边就会形成\(3\)种构成的连通块: 由点\(i\)本身构成. 由点\(i\)的子树(搜索树中)形成若干个连通块. 由除点\(i\)及其子树的所有其它点构成一个连通块. 于是我们可以在用\(tarjan\)找割点的过程中计算搜索树中每棵子树的大小,并统计答案即可. #include<cstdio>…
题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(2*(n-1)\) 如果这个点是割点,那么答案就是两两被分开的联通分量之间求组合数. 代码 #include <bits/stdc++.h> #define ll long long using namespace std; const int N = 500005; struct edge { int to, nt; } E[N << 1]; int dfn[N], low[N], H[N], sz[N];…
题目描述 The first stage of train system reform (that has been described in the problem Railways of the third stage of 14th Polish OI. However, one needs not be familiar with that problem in order to solve this task.) has come to an end in Byteotia. The…
P3477 [POI2008]PER-Permutation 题目描述 Multiset is a mathematical object similar to a set, but each member of a multiset may have more than one membership. Just as with any set, the members of a multiset can be ordered in many ways. We call each such or…
P3478 [POI2008]STA-Station 题目描述 The first stage of train system reform (that has been described in the problem Railways of the third stage of 14th Polish OI. However, one needs not be familiar with that problem in order to solve this task.) has come…
P3467 [POI2008]PLA-Postering 题目描述 All the buildings in the east district of Byteburg were built in accordance with the old arbitecture: they stand next to each other with no spacing inbetween. Together they form a very long chain of buildings of dive…
P3469 [POI2008]BLO-Blockade https://www.luogu.org/problem/P3469 题目描述 There are exactly nn towns in Byteotia. Some towns are connected by bidirectional roads. There are no crossroads outside towns, though there may be bridges, tunnels and flyovers. Ea…
题目 割点模板题. 可以将图中的所有点分成两部分,一部分是去掉之后不影响图的连通性的点,一部分是去掉之后影响连通性的点,称其为割点. 然后分两种情况讨论,如果该点不是割点,则最终结果直接加上2*(n-1).如果是的话,就求子树的每块连通块大小. 一个点的子树可以分成两类:存在返祖边或不存在. 对于前者,割掉该点并不影响连通性,所以和祖先算作一个联通块: 对于后者,割掉该点将使得其变为独立的联通块,所以在搜索时顺便计算\(size\). 于是可以方便地算出后者的\(size\)之和sum,而前者总…
1.根节点,有2棵及以上子树 2.非根节点,有子节点dfn[u]<=low[v] #include <bits/stdc++.h> #define N 1000050 using namespace std; inline int read(){ ,f=;char ch=getchar(); ;ch=getchar();} )+(x<<)+(ch^);ch=getchar();} return x*f; } int head[N],dfn[N],low[N],cut[N];…
题目大意:给定 N 个点,M 条边的联通无向图,求出对于每个点来说,将与这个点相连的所有边都去掉后,会少多少个联通的点对 (x,y). 题解:连通性问题从 DFS 树的角度进行考虑.对于 DFS 树当前的节点来说,若其子节点的 low[] 大于等于子树根节点的时间戳,则将该节点的边去掉后,以该子树的孩子节点为根的子树会和其余部分不连通,会对答案产生一个贡献.诸如此类分析即可得到总共的答案. 代码如下 #include <bits/stdc++.h> using namespace std; c…