Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAXN = 100;
- int used[MAXN+1],Q[MAXN],P[MAXN],G[MAXN][MAXN] = {0},N,M,b,e, area = 1, biggestArea = 0, areaInd;
- void make_empty(){b=0;e=-1;}
- void push(int x){Q[++e]=x;}
- int pop(){return Q[b++];}
- bool emptyQ(){return b>e;}
- void BFS(int r) {
- int x,y,i;
- make_empty();push(r);used[r]=area;P[r]=0;
- int br = 1;
- while(!emptyQ()) {
- x=pop();
- for(i=1;i<=G[x][0];i++) {
- y=G[x][i];
- if(!used[y]) {
- push(y);
- used[y]=area;
- br++;
- P[y]=x;
- }
- }
- }
- if( biggestArea < br ) {
- biggestArea = br;
- areaInd = area;
- }
- }
- int main(){
- for( int i=1;i<=N;i++) used[i]=0;
- cin >> N >> M;
- int x,y;
- while( M-- ){
- cin >> x >> y;
- G[x][++G[x][0]] = y;
- G[y][++G[y][0]] = x;
- }
- for(int i=1;i<=N;i++) {
- if(used[i]==0) BFS(i), area++;
- }
- cout << biggestArea << endl;
- for(int i=1; i<=N; i++ ) if ( used[i] == areaInd ) cout << i <<" ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment