[POI2008] BLO-Blockade, Luogu's experience of improvement, strong connected component

The subject

      [POI2008]BLO-Blockade

      This question is amazing~

      Let's think about the relationship between two points not being connected and being strongly connected.

      So in fact, it is obvious that if the child node traversed by the current point cannot traverse to the ancestor node, it means that the child node can only go to the ancestor node through this point, and the number of ordered point pairs generated in this way is son[x]*( n-son[x]-1)*2, (assuming the current point is x, the son node is son[x])

      Therefore, a concept can be extended - cut point. The cut point is that after the point is removed, the original image is divided into more connected blocks.

      So we judge whether the son can only reach the ancestor node through this point, if so, we need to add the answer, otherwise it is ignored.

      Look at the code specifically, I don't know how to judge the suggestion to learn it

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<iostream>
using namespace std;

int m;
long long n;
struct edge{
	int y,next,x;
}s[1000010];
struct node{
	int dfn,low;
}on[100010];
long long ans[100010];
int first[100010];
long long size[100010];
int len ​​= 0;
int now=0;

void ins(int x,int y){
	len ++;
	s[len].y=y;s[len].next=first[x];first[x]=len;
}

void Tarjan(int x){
	op[x].low=op[x].dfn=++now;
	size[x]=1;
	long long t=0;
	for(int i=first[x];i!=0;i=s[i].next){
		int y=s[i].y;
		if(op[y].dfn==0){//If y has not been traversed
			Tarjan(y);//Search down
			size[x]+=size[y];//size[x] represents the size of the subtree of x
			if(op[y].low<op[x].low) op[x].low=op[y].low;//Update your own low with the low of the child node
			if(op[x].dfn<=op[y].low){//Yes, op[x].dfn<=op[y].low means that y cannot traverse to ancestors and other non-identical paths through other paths subtree node, i.e. x is the cut point
				ans[x]+=t*size[y];//t represents the previous point, multiplying t by size[y] means that each point of the subtree where y is located cannot reach the previous t points.
				t+=size[y];//Update t
			}
		}
		else if(op[y].dfn<op[x].low) op[x].low=op[y].dfn;//更新low
	}
	ans[x]+=t*(nt-1);//The point of this subtree cannot reach the ancestor
}

int main(){
	scanf("%lld %d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		ins(x,y),ins(y,x);//Build edges for undirected graphs
	}
	for(int i=1;i<=n;i++)
		if(op[i].dfn==0) Tarjan(i);//Run Tarjan to calculate the answer
	for(int i=1;i<=n;i++)
		printf("%lld\n",(ans[i]+n-1)<<1);//Output, remember to add (n-1)*2, because this point cannot go to other n-1 points, multiplied by two because the two-way point pair
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325978126&siteId=291194637