Pagini recente » Cod sursa (job #70975) | Cod sursa (job #2174727) | Cod sursa (job #660367) | Cod sursa (job #466032) | Cod sursa (job #1131519)
#include <fstream>
#include <vector>
#include <queue>
#define maxn 30001
#define vint vector<int>::iterator
using namespace std;
ifstream fin("count.in");
ofstream fout("count.out");
vector<int> G[maxn];
priority_queue <pair<int,int> , vector<pair<int,int> >, greater<pair<int,int> > > H;
int n,m,a,b,deg[maxn];
int t,st[6],cnt,maxv;
bool viz[maxn];
void back (int k, int x)
{
if (t+1 > maxv)
{
maxv = t+1;
cnt = 1;
}
else if (t+1 == maxv)
{
++cnt;
}
for (; k < G[x].size(); ++k)
{
if (viz[G[x][k]]) continue;
bool ok=1;
for (int i=1; i<=t; ++i)
{
ok = 0;
for (vint it = G[st[i]].begin(); it != G[st[i]].end(); ++it)
{
if (*it == G[x][k])
{
ok = 1;
break;
}
}
if (ok == 0)
{
break;
}
}
if (ok)
{
st[++t] = G[x][k];
back (k+1,x);
--t;
}
}
}
int main()
{
fin>>n>>m;
for (int i=1; i<=m; ++i)
{
fin>>a>>b;
G[a].push_back (b);
G[b].push_back (a);
deg[a]++;
deg[b]++;
}
for (int i=1; i<=n; ++i)
{
H.push (make_pair (deg[i],i));
}
while (!H.empty())
{
int x = H.top().second;
H.pop ();
if (viz[x])
continue;
viz[x] = 1;
t=0;
back (0,x);
for (vint it = G[x].begin();it != G[x].end(); ++it)
{
deg[*it]--;
H.push (make_pair (deg[*it],*it));
}
}
fout<<maxv<<" "<<cnt;
}