1098: [POI2007] office building biu__ linked list

Source: Internet
Author: User
1098: [POI2007] office building BiuTime limit:20 Sec Memory limit:162 MB
submit:1122 solved:509
[Submit] [Status] [Discuss] Description

FGD opened a telephone company. He hired n clerks and gave each clerk a cell phone. Every employee's cell phone is stored with a few colleagues.
Phone number. As FGD's company expands, the old office building has become so narrow that FGD decided to relocate the company to some new offices. FG
D want staff to be housed in as many office buildings as possible, which will have a relatively better working environment for every employee. However, in order to
For convenience, if two employees are housed in two different office buildings, they must have each other's telephone number. Input

The first row contains two integers N (2<=n<=100000) and M (1<=m<=2000000). The clerk is numbered sequentially 1,2,......, N. The following M line, each
Row contains two positive numbers a and B (1<=a Output

contains two lines. The first line contains a number s, which indicates the number of office buildings that the FGD can place in the staff. The second line contains s from a small to large array
Number, each number followed by a space, indicating the number of employees arranged in each office. Sample Input 7 16
1 3
1 4
1 5
2 3
3 4
4 5
4 7
4 6
5 6
6 7
2 4
2 7
2 5
3 5
3 7
1 7
Sample Output 3
1 2 4 HINT

FGD can arrange staff 4 into an office building, staff 5 and staff 7 arranged into the 2nd office Building, the others into the Office Building No. 3rd.

Source

[Submit] [Status] [Discuss]
Obviously, the answer to the question is to use all the missed edges to graph, and then to count the number and size of connected blocks of the graph. but it's too much. string all the dots into a list every time to take the chain first into the team, all the side search, the chain list did not find the point from the linked list delete the team so repeat straight list empty so the remaining points after each deletion are equivalent to the number of sides of the current point The total order of magnitude is O (m)

#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <

cstring> #include <cmath> #include <vector> #include <queue> using namespace std;

const int MAXN = 1E5 + 10; struct data{int Pre,nex;}

A[MAXN];

int N,TOT,M,TI,PRE[MAXN],NEX[MAXN],ANS[MAXN],VIS[MAXN],P[MAXN];
Vector <int> V[MAXN];

Queue <int> q;
	int main () {#ifdef Yzy freopen ("Yzy.txt", "R", stdin);
	#endif cin >> n >> m;
		while (m--) {int x,y; scanf ("%d%d", &x,&y); V[x].push_back (y);
	V[y].push_back (x);
	for (int i = 1; I <= n; i++) pre[i] = i-1,nex[i] = i+1; Nex[0] = 1; 
	Pre[n+1] = n; 
		while (Nex[0]!= n+1) {++tot; ++ans[tot]; Q.push (nex[0)); Nex[0] = nex[nex[0]];
		Pre[nex[0]] = 0;
			while (!q.empty ()) {int k = Q.front (); Q.pop (); ++ti;
			for (int i = 0; i < v[k].size (); i++) vis[v[k][i]] = TI; for (int x = nex[0]; x!= n+1 x = nex[x]) if (vis[x]!= ti) {nex[pre[x]] = nex[x];
					PRE[NEX[X]] = pre[x]; ++ans[tot];
				Q.push (x);
	} printf ("%d\n", tot);
	Sort (ans + 1,ans + tot + 1);
	for (int i = 1; I <= tot i++) printf ("%d", ans[i]);
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.