Cod sursa(job #1938069)

Utilizator cella.florescuCella Florescu cella.florescu Data 24 martie 2017 16:39:22
Problema Count Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3e4;

unordered_set <int> g[MAXN + 1];
queue <int> q;
bool inq[MAXN + 1];
int x, y;

inline void check_sol(int num) {
  if (num > x) {
    x = num;
    y = 1;
  } else if (num == x)
    ++y;
}

vector <int> v;
int st[6];

void bkt(int pos, int num, int n, int k) {
  if (num == k) {
    check_sol(k + 1);
    return;
  }
  if (pos == n)
    return;
  bkt(pos + 1, num, n, k);
  st[num] = v[pos];
  bool ok = true;
  for (int i = 0; i < num; ++i)
    if (g[st[i]].count(v[pos]) == 0)
      ok = 0;
  if (ok)
    bkt(pos + 1, num + 1, n, k);
}

void clic(int node) {
  v.clear();
  for (auto it : g[node])
    v.push_back(it);
  bkt(0, 0, v.size(), 3);
  bkt(0, 0, v.size(), 2);
}

int main()
{
    int n, m, node;
    ifstream fin("count.in");
    fin >> n >> m;
    for (int i = 0; i < m; ++i) {
      fin >> x >> y;
      g[x].insert(y);
      g[y].insert(x);
    }
    for (int i = 1; i <= n; ++i)
      if (g[i].size() < 6) {
        q.push(i);
        inq[i] = 1;
      }
    x = 2; y = m;
    while (q.empty() == false) {
      node = q.front();
      q.pop();
      clic(node);
      for (auto it : g[node]) {
        g[it].erase(node);
        if (g[it].size() < 6 && inq[it] == 0) {
          q.push(it);
          inq[it] = 1;
        }
      }
    }
    ofstream fout("count.out");
    fout << x << " " << y << '\n';
    fout.close();
    return 0;
}