# bzoj 1064 noi2008 假面舞会题解

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
struct Edge
{
int next;
int to;
int val;
}edge[2000005];
int dep[100005];
int cnt=1;
int d;
int n,m;
int maxdep,mindep=0x3f3f3f3f;
bool used[100005];
void init()
{
cnt=1;
}
int gcd(int x,int y)
{
if(y==0)
{
return x;
}
return gcd(y,x%y);
}
{
edge[cnt].to=r;
edge[cnt].val=w;
}
void dfs(int x,int deep)
{
used[x]=1;
dep[x]=deep;
maxdep=max(maxdep,dep[x]);
mindep=min(mindep,dep[x]);
{
int to=edge[i].to;
if(!used[to])
{
dfs(to,deep+edge[i].val);
}else
{
d=gcd(d,abs(deep+edge[i].val-dep[to]));
}
}
}
{
int f=1,x=0;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;
}
int main()
{
//    freopen("party.in","r",stdin);
//    freopen("party.out","w",stdout);
init();
for(int i=1;i<=m;i++)
{
}
int ret=0;
for(int i=1;i<=n;i++)
{
if(!used[i])
{
maxdep=0;
mindep=0x3f3f3f3f;
dfs(i,1);
ret+=maxdep-mindep+1;
}
}
if(!d)
{
if(ret>=3)
{
printf("%d 3\n",ret);
return 0;
}else
{
printf("-1 -1\n");
return 0;
}
}else
{
if(d<3)
{
printf("-1 -1\n");
return 0;
}
for(int i=3;i<=d;i++)
{
if(d%i==0)
{
printf("%d %d\n",d,i);
return 0;
}
}
}
}

posted @ 2018-09-15 14:12  lleozhang  Views(60)  Comments(0Edit  收藏
levels of contents