11785 - Hypercube

All about problems in Volume 117. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

11785 - Hypercube

Post by durjay »

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[1025],cu[1025];
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[0]=c;
du[1]=s;
e=2;
cu[0]=1;
cu[1]=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 .

Post by serur »

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

Post Reply

Return to “Volume 117 (11700-11799)”