Page 2 of 2

Posted: Mon Oct 29, 2007 7:19 am
by sabir
Code modefied.But still WA.

Code: Select all

#include <stdio.h>
#include <math.h>

#define sz 20

long par[sz];
long n,vertex,count;
long mat[sz][sz];
long visit[sz],ans[sz];
bool flag;

void DfsVisit(long node)
{
	long i;

	visit[node]=1;
	
	if(n+1==count)
	{
		printf("(1,");
		flag=false;
		for(i=1;i<=n;i++)
		{
			printf("%ld", ans[i]);
			if(i<n)
			{
				printf(",");
			}
		}
		printf(")\n");
		return;
	}

	for(i=1;i<=vertex;i++)
	{
		if(mat[node][i]==1)
		{
			if(visit[i]==0)
			{
				ans[count]=i;
				count++;
				DfsVisit(i);
				visit[i]=0;
				count--;
			}
		}
	}
	return;
}

void Dfs()
{
	long i;

	for(i=1;i<=vertex;i++)
	{	
		par[i]=0;
		visit[i]=0;
	}

	DfsVisit(1);
}

int main()
{
	freopen("677.txt", "w", stdout);

	long i,j;
	bool tag=false;

	while(scanf("%ld %ld", &vertex, &n)==2)
	{
		flag=true;
		if(tag==true)
		{
			printf("\n");
		}

		tag=true;

		count=1;
		for(i=1;i<=vertex;i++)
		{
			for(j=1;j<=vertex;j++)
			{
				mat[i][j]=0;
			}
		}

		for(i=1;i<=vertex;i++)
		{
			for(j=1;j<=vertex;j++)
			{
				scanf("%ld", &mat[i][j]);
			}
		}

		Dfs();

		if(flag==true)
		{
			printf("no walk of length n\n");
		}
		if(scanf("%ld", &i)!=1)
		{
			break;
		}
	}
	return 0;
}

Re: 677 Why WA??? please help me

Posted: Fri Apr 04, 2008 5:51 pm
by turcse143
i think there is problem in this section.

Code: Select all

 
         if(visit[i]==0)
         {
            ans[count]=i;
            count++;
            DfsVisit(i);
            visit[i]=0;
            count--;
         }
i think visit=0 when the loop is complete & u return to the previous node.

Re: 677 - All Walks of length "n" from the first node

Posted: Wed Oct 17, 2012 9:48 am
by Mukit Chowdhury
Getting WA !!! Please help !!!

Code: Select all

while(1)
{
printf("Accepted....... :D\n");
}