Page 1 of 2
677 - All Walks of length "n" from the first node
Posted: Sat Mar 22, 2003 9:11 am
by yahoo
Code: Select all
#include<stdio.h>
#define N 20
int n,d,time,a[N][N],b[N],path;
char color[N];
void dfs(int s)
{
int i;
if(time==(d+1))
{
path++;
printf("{");
for(i=0;i<=d;i++)
{
if(i) printf(",");
printf("%d",b[i]+1);
}
printf("}\n");
return ;
}
for(i=0;i<n;i++)
if(color[i]=='w' && a[s][i])
{
color[i]='g';
b[time++]=i;
dfs(i);
b[--time]=0;
color[i]='w';
}
}
main()
{
freopen("c:\\in.txt","r",stdin);
int cases=0,i,j;
while(1)
{
if(cases) scanf("%d",&d);
if(scanf("%d%d",&n,&d)==EOF) break;
if(cases) printf("\n");
cases++;
for(i=0;i<n;i++) for(j=0;j<n;j++) scanf("%d",&a[i][j]);
for(i=0;i<n;i++) color[i]='w'; time=path=0;
time=1;
color[0]='g';
dfs(0);
if(path==0) printf("no walk of length %d\n",d);
}
return 0;
}
here goes my code..
i think it's not hard to read and realize..
but why wa for just a simple problem..
dominik, tomal bhai .. and to all please help..
i am very crazy to solve it.. by just dfs..
please helpp......
drowning anupam....

[/b]
Posted: Sat Mar 22, 2003 11:30 am
by saiqbal
i think your terminating condition is not right.
i can remember that i terminated when i expected -9999 but got something else.
it might help.
thanx
-sohel
677:What is input terminate condition?
Posted: Sat Sep 06, 2003 1:23 pm
by erfan
What is the terminate condition of it i cannot realize.
I terminate input just :
Code: Select all
if(flag) scanf("%ld",&d);
if(scanf("%ld%ld",&n,&d)!=2) break;
If it is right may my algorithm is wrong.Pls provide some critical input/output to judge my code.
Pls anybody help me.
Posted: Sat Sep 06, 2003 1:45 pm
by ei01036
As i understand, the input termitation condition is related with that -9999. When it doen's exists, you can be sure you're not between test cases, therefore you're ate the end.
Posted: Sat Apr 17, 2004 6:14 am
by felix_halim
Maybe you forgot to print "no walk of length n" if the path doesn't exist
Don't forget! n is variable!
You should printf("no walk of length %d\n",n);
instead of puts("no walk of length n");
Re: what's wrong with 677
Posted: Sat Apr 17, 2004 7:11 am
by anupam
[quote="yahoo"]
Code: Select all
if(path==0) printf("no walk of length %d\n",d);
From the above code segment you can feel that
I have checked that..
But still wa...
--
Anupam
Posted: Sat Apr 17, 2004 9:37 am
by dvntae
it's funny 2 find out that ur program is completely perfect (even no problem with the -9999), the only reason why it's WA is ur using the wrong bracket. replace the bracket: "{}" with "()" and done...
next time, use glasses. u maybe need 1. =) hehhehe..
Posted: Sat Apr 17, 2004 11:38 am
by anupam
I already use one....
Yahoo also uses....
Thank you for your advice..
Better be a doctor....
--
Anupam
very simple
Posted: Sun Feb 13, 2005 8:27 am
by rushel
I was having the same problem.
but when i read the following line from the problem carefully i got AC
the line:
Separate the output of the different cases by a blank line.
if( N == -9999 ) {
cout << endl;
continue;
}

677 Why WA??? please help me
Posted: Wed Aug 10, 2005 11:59 pm
by sacrebar
It's my code, please help me, I don`t understand my error
Re: 677 Why WA??? please help me
Posted: Thu Sep 01, 2005 2:57 am
by sacrebar
El codigo esta bien solo le falta un vector de visitas antes de llamar ala recursi
Posted: Thu Sep 01, 2005 10:50 am
by Dominik Michniewski
Sacrebar:
Please translate your message into englisch - it could be useful for other people, which will be search for hints

and if your code is accepted, remove your code
Best regards
DM
Posted: Tue Oct 23, 2007 9:28 am
by sabir
i am getting WA in this code.plz help.
Posted: Fri Oct 26, 2007 5:24 am
by sapnil
To sabir,
you may miss this line.
Code: Select all
In case there are not walks of length n, just print `no walk of length n'
Thanks
Keep posting
Sapnil