Cod sursa(job #1846573)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 13 ianuarie 2017 14:21:15
Problema Count Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.98 kb
#include<fstream>
#include<set>
#define DIM 30005
using namespace std;
int n, m, maxim, nr, p, u, i, x, y, nod;
int c[DIM], g[DIM], viz[DIM];
set<int> v[DIM];
ifstream fin("count.in");
ofstream fout("count.out");
void verif(int nod){
    int i, num, n = 0, ii, j, ok;
    int a[7], w[7];
    set<int>::iterator it = v[nod].begin();
    while(it != v[nod].end()){
        if(viz[ *it] == 1){
            w[++n] = *it;
            a[n - 1] = 0;
        }
        it++;
    }
    for(i = 1; i <= n; i++){
        for(j = i + 1; j <= n; j++){
            if(v[ w[i] ].find(w[j]) != v[ w[i] ].end()){
                a[i - 1] += (1 << (j - 1) );
                a[j - 1] += (1 << (i - 1) );
            }
        }
        a[i - 1] += (1 << (i - 1));
    }
    for(ii = 0; ii < (1 << n); ii++){
        ok = 1;
        num = 0;
        for(i = 0; i < n; i++){
            if( ( (ii >> i) & 1) == 1 ){
                num++;
                if( (a[i] & ii) != ii){
                    ok = 0;
                }
            }
        }
        if(ok == 1){
            num++;
            if(num > maxim){
                maxim = num;
                nr = 1;
            }
            else{
                if(num == maxim){
                    nr++;
                }
            }
        }
    }
}
int main(){
    fin>> n >> m;
    for(i = 1; i <= m; i++){
        fin>> x >> y;
        g[x]++;
        g[y]++;
        v[x].insert(y);
        v[y].insert(x);
    }
    p = 1;
    for(i = 1; i <= n; i++){
        viz[i] = 1;
        if(g[i] <= 5){
            c[++u] = i;
        }
    }
    while(p <= u){
        nod = c[p];
        verif(nod);
        viz[nod] = 0;
        for(i = 1; i <= n; i++){
            if(viz[i] == 0){
                continue;
            }
            g[i]--;
            if(g[i] == 5){
                c[++u] = i;
            }
        }
        p++;
    }
    fout<< maxim <<" "<< nr <<"\n";
    return 0;
}