Bzoj 1098: [POI2007] office building biu__ linked list

Source: Internet
Author: User
Description

FGD opened a telephone company. He hired n clerks and gave each clerk a cell phone. Each employee's phone has a number of colleagues in it. As FGD's company expands, the old office building has become so narrow that FGD decided to relocate the company to some new offices. FGD wants staff to be housed in as many office buildings as possible, which will have a relatively better working environment for every employee. However, for the sake of 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 lines, each containing 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 the number of s from small to large, each 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.


This problem can be found that the complementary map of the Unicom block must be put together

Then we just need to build a patch and then bfs it.

But it will be timed out.

What to do. Link list optimization at BFS traversal point.

Through the point can no longer query whether or not with the current point of the patch edge

#include <queue> #include <cstdio> #include <algorithm> using namespace std;
     struct line {int s,t;
int next;
}A[4000001];
int head[100001];
int edge;
     inline void Add (int s,int t) {A[edge].next=head[s];
     Head[s]=edge;
     A[edge].s=s;
a[edge].t=t;
     } struct point {int next;
int pre;
}L[100001];
Queue <int> Q;
int SS;
int ans[100001];
BOOL v[100001],vx[100001];
     inline void del (int i) {l[l[i].pre].next=l[i].next;
L[l[i].next].pre=l[i].pre;
     } inline void BFs () {int i;
          while (l[0].next!=0) {int d=l[0].next;
          Del (d);
          Q.push (d);
          V[d]=true;
          int S=1; while (!
          	   Q.empty ()) {D=q.front ();
               Q.pop ();
               for (I=head[d];i!=0;i=a[i].next) vx[a[i].t]=true;
               	for (I=l[0].next;i!=0;i=l[i].next) {if (!v[i]&&!vx[i]) {         s++;
               	         V[i]=true;
                         Q.push (i);
                    Del (i);
          } for (I=head[d];i!=0;i=a[i].next) Vx[a[i].t]=false;
          } ss++;
     Ans[ss]=s;
     int main () {int n,m;
     scanf ("%d%d", &n,&m);
     int i;
     int s,t;
          for (i=1;i<=m;i++) {scanf ("%d%d", &s,&t);
          edge++;
          Add (s,t);
          edge++;
     Add (t,s);
     } l[0].next=1;
          for (i=1;i<=n;i++) {l[i].pre=i-1;
     l[i].next=i+1;
     } l[n].next=0;
     BFS ();
     printf ("%d\n", SS);
     Sort (ANS+1,ANS+1+SS);
    for (i=1;i<=ss;i++) printf ("%d", ans[i]);
     printf ("%d\n", 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.