Cod sursa(job #344709)
#include <algorithm>
#include <stdio.h>
#include <set>
#define MAX 32768
using namespace std;
set <int> setVec[MAX];
int n, m, nrVec, nodMax, nrGraf, dimHeap;
int poz[MAX], vctVec[MAX], vecini[MAX], sel[MAX];
int heapVec[MAX];
inline void val(int lvl, int lt)
{
if (lvl > nrVec)
{
if (nodMax < lt)
nodMax = lt, nrGraf = 0;
if (nodMax == lt)
nrGraf++;
return;
}
val(lvl + 1, lt);
sel[lvl] = 1;
int ok = 1;
for (int i = 1; i < lvl; i++)
if (sel[i] && (setVec[vctVec[i]].lower_bound(vctVec[lvl]) == setVec[vctVec[i]].end() || (*setVec[vctVec[i]].lower_bound(vctVec[lvl])) != vctVec[lvl]))
ok = 0;
if (ok)
val(lvl + 1, lt + 1);
sel[lvl] = 0;
}
inline void heapUp(int nod)
{
if (nod == 1)
return;
if (vecini[heapVec[nod]] < vecini[heapVec[nod / 2]])
{
swap(heapVec[nod], heapVec[nod / 2]);
swap(poz[heapVec[nod]], poz[heapVec[nod / 2]]);
heapUp(nod / 2);
}
}
inline void heapDown(int nod)
{
if (nod * 2 <= dimHeap)
{
int locMin = nod * 2;
if (nod * 2 < dimHeap && vecini[heapVec[locMin]] > vecini[heapVec[locMin + 1]])
locMin++;
if (vecini[heapVec[nod]] > vecini[heapVec[locMin]])
{
swap(heapVec[nod], heapVec[locMin]);
swap(poz[heapVec[nod]], poz[heapVec[locMin]]);
heapDown(locMin);
}
}
}
int main()
{
freopen("count.in", "r", stdin);
freopen("count.out", "w", stdout);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++)
{
poz[i] = i;
heapVec[i] = i;
}
dimHeap = n;
for (int i = 1; i <= m; i++)
{
int x, y;
scanf("%d %d", &x, &y);
vecini[x]++;
heapDown(poz[x]);
vecini[y]++;
heapDown(poz[y]);
setVec[x].insert(y);
setVec[y].insert(x);
}
for (; dimHeap; dimHeap--)
{
int nodAc = heapVec[1];
swap(heapVec[dimHeap], heapVec[1]);
poz[heapVec[1]] = 1;
heapDown(1);
nrVec = 0;
for (set <int>::iterator setVecIt = setVec[nodAc].begin(); setVecIt != setVec[nodAc].end(); setVecIt++)
{
int vec = (*setVecIt);
setVec[vec].erase(nodAc);
vecini[vec]--;
heapUp(poz[vec]);
vctVec[++nrVec] = vec;
}
val(1, 1);
}
printf("%d %d\n", nodMax, nrGraf);
fclose(stdin);
fclose(stdout);
return 0;
}