# [bzoj1064][Noi2008]假面舞会

#include<iostream>
#include<cstdio>
#define MN 100000
using namespace std;
{
int x = 0 , f = 1; char ch = getchar();
while(ch < '0' || ch > '9'){ if(ch == '-') f = -1;  ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}

bool found=false;
bool inq[MN+5],mark[MN+5];
struct edge{int to,next,kind;}e[MN*20+5];

void ins(int f,int t){
}

inline int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}
inline int abs(int x){return x>0?x:-x;}

void check(int x)
{
x=abs(x);if(!x)return;
if(!found) found=true,ans=x;
else ans=gcd(ans,x);
}

void solve(int x)
{
mx=max(mx,f[x]);mn=min(mn,f[x]);mark[x]=1;
{
if(!mark[e[i].to]) (f[e[i].to]=f[x]+(e[i].kind?1:-1)),solve(e[i].to);
if((f[e[i].to]-f[x]-(e[i].kind?-1:1))!=0)check(f[e[i].to]-f[x]+(e[i].kind?-1:1));
}
}

int get(int x)
{
for(int i=3;i<=x;i++)
if(x%i==0)
return i;
}

int main()
{
for(int i=1;i<=m;i++)
int sum=0;
for(int i=1;i<=n;i++)if(!mark[i])
mx=mn=0,f[i]=0,solve(i),sum+=mx-mn+1;
if(found) printf("%d %d\n",ans>2?ans:-1,ans>2?get(ans):-1);
else printf("%d %d\n",sum>2?sum:-1,sum>2?3:-1);
return 0;
}

posted @ 2017-03-28 12:50  FallDream  阅读(234)  评论(0编辑  收藏