oj1616: FIG communication

Topics requirements
connected graph means that between any two vertices can reach each other's map, give you an N vertices and M edges of non-connected graph, ask the maximum number of edges can be deleted, so this figure is still together.
Input
input comprises the following parts. (Plurality of sets of input)
a first part: two input numbers N (1 <= N <= 100) and M, respectively, the top points and edges of the figure.
Second part: M rows, each row consists of two numbers A, B form, that the there is an edge between the connected vertices A and B, the same edge will not be repeated.
Output
Output up to delete the number of edges.
The Input the Sample
Raw
1 0
the Sample the Output
Raw
0
this problem beginning to see the point of the need to constantly move between two points, wanted to write DFS to find,
China Unicom between two points, the latter point is not used.

void DFS(int x)
{
	
	vis[x]=1;
	for(int y=2;y<=n;y++)
	{
		if((a[x][y]==1||a[y][x]==1)&&vis[y]==0)
				DFS(y);
	}	
}

but! ! ! !
After writing this suddenly I discovered that this problem seems to be a fixed value law issues, China Unicom seen from between the points.
2 1 -----
1 ---- ----- 2. 3;
can 234 as a whole with 1 communication.

Here Insert Picture Description
Digital future is the same reason. Therefore, the number of China Unicom is n-1. This question is now entirely a question of water. . . .

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	int n, m;
	while (cin >> n >> m)
	{
		int x, y;
		for (int i = 1; i <= m; i++)
			cin >> x >> y;
		cout << m - n+1 << endl;
	}
	return 0;
}
Published 38 original articles · won praise 27 · views 3180

Guess you like

Origin blog.csdn.net/qq_45891413/article/details/104999946