## 11785 - Hypercube

Moderator: Board moderators

durjay
New poster
Posts: 13
Joined: Tue Oct 06, 2009 5:09 pm
Location: ctg

### 11785 - Hypercube

In this problem 1st i find out the power of 2.
if this is power of 2 then i check all node have same no of degree.
if this is same i give output yes.else no.
if this not power of two then i also give answer 2.

but i got WA after 0.044s.
here is my code:

#include<stdio.h>
#include<math.h>
int main()
{
long int d,u,r,j,a,y;
long int c,s,e,i,t;
long int du,cu;
while(1)
{
scanf("%ld%ld",&d,&u);
if(d==0&&u==0)
break;
r=0;
for(j=2;j<=32;j++)
{
a=pow(2,j);
if(a==d)
{
r=1;
y=j;
break;
}
if(a>d)
break;
}
if(r==1)
{
for(j=1;j<=u;j++)
{
scanf("%lld%lld",&c,&s);
if(j==1)
{
du=c;
du=s;
e=2;
cu=1;
cu=1;
}
else
{
i=0;
for(a=0;a<e;a++)
{
if(du[a]==c)
{
i=1;
cu[a]=cu[a]+1;
break;
}
}
if(i==0)
{
du[e]=c;
cu[e]=1;
e++;
}
t=0;
for(a=0;a<e;a++)
{
if(du[a]==s)
{
t=1;
cu[a]=cu[a]+1;
break;
}
}
if(t==0)
{
du[e]=s;
cu[e]=1;
e++;
}
}
}
i=1;
for(a=0;a<d;a++)
{
if(cu[a]!=y)
{
i=0;
break;
}
}
if(i==1)
printf("YES\n");
else
printf("NO\n");
}
else
{
for(j=1;j<=u;j++)
scanf("%ld%ld",&c,&s);
printf("NO\n");
}
}
return 0;
}

plz give me some critical input output.

serur
A great helper
Posts: 251
Joined: Thu Feb 23, 2006 11:30 pm

### Re: 11785-WA in hypercube .

Hey, I didn't check your code, but the thing is: there can be edges (i,j) such that either i < 0 or j < 0.
The answer is, of course, "NO".
If there is ever a war between men and machines, it is easy to guess who will start it (c) Arthur Clarke