Pagini recente » Cod sursa (job #604858) | Cod sursa (job #1614879) | Cod sursa (job #1947101) | Cod sursa (job #1995175) | Cod sursa (job #1277524)
#include<fstream>
#include<algorithm>
#include<bitset>
#include<set>
using namespace std;
ifstream fin("count.in");
ofstream fout("count.out");
set <int> q,L[30005];
bitset <30005> ap;
int n,m,x,y,p,aux,st[8],sol[8];
inline void back(const int &k)
{
int i,ok,auxx;
set <int>::iterator it;
for (it=L[st[k-1]].begin();it!=L[st[k-1]].end();++it)
if (!ap[*it])
{
auxx=*it, st[k]=auxx, ap[auxx]=1;
for (i=1,ok=1;i<k;++i)
if (L[auxx].find(st[i])==L[auxx].end())
{
ok=0;
break;
}
if (ok)
{
++sol[k];
if (k<4) back(k+1);
}
ap[auxx]=0;
}
}
int main()
{
int i;
set <int>::iterator it;
fin>>n>>m;
for (i=1;i<=m;++i)
{
fin>>x>>y;
L[x].insert(y);
L[y].insert(x);
}
for (i=1;i<=n;++i)
q.insert(i);
for (i=1;i<=n && !p;++i)
if (L[i].size()<6)
p=i;
q.erase(p);
while (!q.empty())
{
st[1]=p, ap[p]=1;
back(2);
aux=0;
for (it=L[p].begin();it!=L[p].end();++it)
{
int auxx=*it;
L[auxx].erase(p);
if (L[auxx].size()<6 && !aux)
aux=auxx;
}
ap[p]=0;
if (!q.empty())
q.erase(p);
if (!aux)
for (it=q.begin();it!=q.end() && !aux;++it)
if (L[*it].size()<6 && !aux)
aux=*it;
p=aux;
}
sol[3]/=2, sol[4]/=6;
for (i=4;i>0;--i)
if (sol[i])
{
fout<<i<<" "<<sol[i]<<"\n";
break;
}
return 0;
}