Cod sursa(job #1259681)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 10 noiembrie 2014 13:10:30
Problema Count Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.19 kb
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
const string problemName = "count";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";

typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;

const int INF = (1LL << 31) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int NMAX = 30000 + 5;

int N, M, sol3, sol4;
unordered_set<int> V[NMAX];
deque<int> Q;
PII sol;

int main() {
    int i, x, y;

#ifndef ONLINE_JUDGE
    freopen(inputFile.c_str(), "r", stdin);
    freopen(outputFile.c_str(), "w", stdout);
#endif

    scanf("%d%d", &N, &M);

    while(M--) {
        scanf("%d%d", &x, &y);
        V[x].insert(y);
        V[y].insert(x);
    }

    for(i = 1; i <= N; i++)
        if(V[i].size() < 6)
            Q.push_back(i);

    while(!Q.empty()) {
        x = Q.front();
        Q.pop_front();

        for(auto y : V[x])
            if(x < y) {
                for(auto z : V[x])
                    if(y < z && V[y].count(z)) {
                        sol3++;
                        for(auto t : V[x]) {
                            if(V[y].count(t) && V[z].count(t))
                                sol4++;
                        }
                    }
            }

        for(auto y : V[x]) {
            V[y].erase(x);
            if(V[y].size() < 6)
                Q.push_back(y);
        }

        V[x].clear();
    }

    sol = make_pair(1, N);

    if(M)
        sol = make_pair(2, M);

    if(sol3)
        sol = make_pair(3, sol3);

    if(sol4)
        sol = make_pair(4, sol4);

    printf("%d %d\n", sol.first, sol.second);

    return 0;
}