Logu P3225 [HNOI2012] Mine set up __ graph theory

Source: Internet
Author: User
Topic Description

The coal mine site can be regarded as a non-direction diagram composed of a tunnel connected with a coal-digging point. For the sake of safety, it is hoped that all coal-digging workers will have a way out to the rescue exit at the accident site. The miner decided to set up a rescue exit at some of the coal-digging sites so that no matter which coal-digging point collapsed, the other miners had a road to the rescue exit.

Please write a program that calculates the total number of settings that need to be set up at least several relief exits and different minimum relief exits. Input output format input format:

The input file has several sets of data, the first row of each set of data is a positive integer N (n<=500), representing the number of tunnels on the site, and the next N rows are two integers separated by a space s and T, which means that the dug s and the coal point T are directly connected by the tunnel. The input data ends with 0.

Output format:

How many sets of data are in the input file, and how many rows are in the output file output.txt. Each row corresponds to the result of a set of input data. The first line of the case I: Start (note case, case and I have a space, I and: there is no space between: there are spaces, followed by a space separated by two positive integers, the first positive integer indicates that for the first group I input data need to set up at least a few rescue exits, the second positive integer for the first The total number of setup schemes for the minimum rescue exit for group input data. The input data guarantees that the answer is less than 2^64. The output format refers to the following input and output samples.

input and Output sample input Sample #:

1  3
4  1
3  5 1 2 2
6 1 5 6 3 1 6-3  2
1  2
, 1 3 2 4 2 5 3 6 3 7 0
Output Sample #:
Case 1:2 4 Case
2:4 1

The four groups in case 1 were (2,4), (3,4), (4,5), (4,6);

A set of solutions for Case 2 is (4,5,6,7).

True TM question.

This is the point of the cut ... Because removing a point the whole diagram does not connect will add the answer.
But only a side, so if deleted after the cut point of a unicom block connected to the number of cut points >=2, then this unicom block without setting up rescue.
Note: If the entire graph is a double unicom component, then the number of scenarios = (n (n-1)/2)
The above content is excerpted from Chaijing's blog

#include <iostream> #include <cstring> #include <cstdio> using namespace std;
const int m=505;
int n,m,cnt,t,t,tim,num,sz,hd[m],dfn[m],low[m];
Long ans;
BOOL B[m],vis[m],ha[m]; struct Edge {int to,nxt;}
	void Addedge (int x,int y) {v[++cnt].to=y;
	} void Tarjan (int u,int fa) {int ch=0;
				for (int i=hd[u];i;i=v[i].nxt) if (V[I].TO!=FA) {if (!dfn[v[i].to)) {Tarjan (v[i].to,u);
				Low[u]=min (low[u],low[v[i].to]);
			if (dfn[u]<=low[v[i].to]) b[u]=1;
		else Low[u]=min (low[u],dfn[v[i].to]);
} if (!fa&&ch==1) b[u]=0;
	} void Dfs (int u,int fa) {vis[u]=1;
			for (int i=hd[u];i;i=v[i].nxt) if (V[I].TO!=FA) {if (!vis[v[i].to]&&!b[v[i].to)) DFS (V[I].TO,U);
		else if (b[v[i].to]&&!ha[v[i].to]) ha[v[i].to]=1,sz++;
		int main () {while (scanf ("%d", &m) &&m) {cnt=0;
		n=0; memset (Dfn,0,sizEOF (DFN));
		memset (low,0,sizeof (Low));
		memset (hd,0,sizeof (HD));
		Memset (b,0,sizeof (b));
		memset (Vis) (vis,0,sizeof);
			for (int i=1;i<=m;i++) {int x,y;
			scanf ("%d%d", &x,&y);
			Addedge (X,y), Addedge (y,x);
		N=max (N,max (x,y));
		for (int i=1;i<=n;i++) if (!dfn[i]) Tarjan (i,0);
				for (int i=1;i<=n;i++) if (!vis[i]&&!b[i]) {memset (ha,0,sizeof (ha));
				DFS (i,0);
			if (sz==1) t++,ans*= (long Long) num;
			} if (!t) {ans= (Long long) n (n-1)/2;
		printf ("Case%d:2%lld\n", ++t,ans);
	else printf ("Case%d:%d%lld\n", ++t,t,ans);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.