[ create a new paste ] login | about

Link: http://codepad.org/ledBH9qX    [ raw code | fork ]

iamyeasin - C++, pasted on Feb 3:
#include <bits/stdc++.h>
#define VIS 1
#define UNVIS 0

using namespace std;

typedef vector <bool> vb;
typedef vector <int> vi;

const int MAX = 200005;

int V,E,counter=0;
vector < vi > Graph;
vector < vb > Check;
vector < int > num;
bool visited[MAX];

void PrintGrid()
{
    for(int i=0; i<V; i++)
    {
        for(int j=0; j<Graph[i].size(); j++)
        {
            cout << Graph[i][j] << " ";
        }
        puts("");
    }
}

void Input()
{
    for(int i=0; i<V; i++)
    {
        for(int j=0; j<V; j++)
        {
            Graph[i].push_back(j);
        }
    }
}

void FUCK()
{
    for(int i=0; i<Graph.size(); i++)
    {
        for(int j=0; j<Graph[i].size(); j++)
        {
            if(!Check[i][j])cout << Graph[i][j] << " ";
        }
        cout << endl;
    }
}

void dfs(int u)
{
    visited[u] = VIS;
    for(int i=0; i<Graph[u].size(); i++)
    {
        int v = Graph[u][i];
        if(!visited[v] && !Check[u][i])
        {
            ++counter;
            dfs(v);
        }
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
    cin >> V >> E;
    memset(visited, false, sizeof visited);
    Check.assign(V, vb(V, false));
    Graph.assign(V, vi());
    num.clear();
    Input();
//    PrintGrid();
    for(int i=0; i<E; i++)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        Check[a][b] = 1;
        Check[b][a] = 1;
    }
//    PrintGrid();
//    FUCK();
    for(int i=0; i<V; i++)
    {
        counter=0;
        if(visited[i] == UNVIS )
        {
            dfs(i);
//            printf("\n");
            num.push_back(counter);
        }
    }
    cout << num.size() << endl;
    sort(num.begin(),num.end());

    for ( auto obj: num)
    {
        cout << obj+1 << " ";
    }
    cout << endl;


    return 0;
}


Create a new paste based on this one


Comments: