bzoj 4316 independent set of small C

LINK: independent set of small C

Undirected graph largest independent set problem is NPC's.

Independent sets tree is a maximum independent set of fixed bipartite graph is a network flow (total points - the maximum number of matches.

This question is to find a cacti largest independent set.

We consider the problem with tree rings and almost non-ring.

Sheung point rather special addition to his son, there are restrictions on their own as well as restrictions on the two rings on it.

Dp direct acyclic tree can be resolved.

Therefore, a two-step tree dp + dp solved by double ring communication components required to seek or ring.

I am here to put dp practice: split into chain here do not like, practice ring before I forgot.

X consider violence enumeration state found that only two selected for the violence we handpicked the first two points do not choose this option last point is not on the list.

If not selected then the second and last point does not matter. Doing so can prove to be correct. (Facilitated optimal all state space.

inline void solve(int x)
{
	g[2][0]=g[2][1]=f[a[2]][0];
	rep(3,sum,i)
	{
		g[i][0]=max(g[i-1][1],g[i-1][0])+f[a[i]][0];
		g[i][1]=g[i-1][0]+f[a[i]][1];
	}
	f[x][1]+=g[sum][0];//开头为0结尾也为0.
	g[2][1]=f[a[2]][1];g[2][0]=f[a[2]][0];
	rep(3,sum,i)
	{
		g[i][0]=max(g[i-1][1],g[i-1][0])+f[a[i]][0];
		g[i][1]=g[i-1][0]+f[a[i]][1];
	}
	f[x][0]+=max(g[sum][0],g[sum][1]);
}
inline void dfs(int x)
{
	dfn[x]=low[x]=++cnt;
	s[++top]=x;f[x][1]=1;
	go(x)
	{
		if(!dfn[tn])
		{
			dfs(tn);
			low[x]=min(low[x],low[tn]);
			if(low[tn]>=dfn[x])
			{
				int y=0;sum=0;
				a[++sum]=x;
				while(y!=tn)
				{
					y=s[top--];
					a[++sum]=y;
				}
				solve(x);
			}
		}
		else low[x]=min(low[x],dfn[tn]);
	}
}
int main()
{
	freopen("1.in","r",stdin);
	get(n);get(m);
	rep(1,m,i)
	{
		int x,y;
		get(x);get(y);
		add(x,y);add(y,x);
	}
	dfs(1);put(max(f[1][0],f[1][1]));
	return 0;
}

Guess you like

Origin www.cnblogs.com/chdy/p/12620394.html