洛谷 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 to an end in Byteotia. The…
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…
BZOJ原题链接 洛谷原题链接 若第\(i\)个点不是割点,那么只有这个点单独形成一个连通块,其它点依旧连通,则答案为\(2\times (n-1)\). 若第\(i\)个点是割点,那么去掉这个点相关的边就会形成\(3\)种构成的连通块: 由点\(i\)本身构成. 由点\(i\)的子树(搜索树中)形成若干个连通块. 由除点\(i\)及其子树的所有其它点构成一个连通块. 于是我们可以在用\(tarjan\)找割点的过程中计算搜索树中每棵子树的大小,并统计答案即可. #include<cstdio>…
题面 设\(dp_i\)表示以\(i\)为根节点时所有节点的深度之和. 首先以 \(1\) 为根求出所有点深度之和\(dp_1\),并预处理每个点的子树大小. 设 \(v\) 是 \(u\) 的孩子,考虑根从 \(u\) 移动到 \(v\) 对 \(dp_v\) 产生的影响. 不难发现,\(v\) 子树内所有点深度 \(−1\),其余点深度 \(+1\). 即 \(dp_v = dp_u − size_v + (n − size_v)\). 再 \(\text{DFS}\) 一次即可求出所有的…
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…
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,而前者总…
一道经典的割点例题,用size数组记录该子树有多少个节点,sum是这棵搜索树上有多少个节点,sum*(n-sum-1)是将点删掉后的数对数量. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 1000010 using namespace std; typedef long long ll; inline int read() { ;…
题目链接 [洛谷传送门] 题解 很显然,当这个点不是割点的时候,答案是\(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];…