Cod sursa(job #1930187)

Utilizator sandupetrascoPetrasco Sandu sandupetrasco Data 18 martie 2017 16:19:48
Problema Componente tare conexe Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <bits/stdc++.h>
#define z(x) (x & (-x))

typedef long long ll;

using namespace std;

int n, m, x, y;
string tmp;
vector < string > VV;
vector < int > V[100100];
set < string > S;

void dfs(int x)
{
    tmp[x-1] = '1';
    for (auto it : V[x])
        if (tmp[it-1] == '0') dfs(it);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ifstream cin("ctc.in");
    ofstream cout("ctc.out");
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
        cin >> x >> y, V[x].push_back(y);
    for (int i = 1; i <= n; i++)
    {
        tmp.clear();
        for (int j = 1; j <= n; j++) tmp += '0';
        dfs(i);
        VV.push_back(tmp);
        S.insert(tmp);
    }
    cout << S.size() << "\n";
    for (auto it : S)
    {
        for (int i = 0; i < VV.size(); i++)
            if (VV[i] == it) cout << i+1 << " ";
        cout << "\n";
    }
    return 0;
}