In the given file named "data.in" are written the number of cities N, two cities A and B and the existing roads between them.Ex, the set "2 6" says that between city 2 and city 6 there exist a road.I have to show in a file named"data.out" all the possibilities to reach city B from city A without going more than once through a city. I have written the following code ,but it doesnt print anything.
#include <stdio.h>
#include <stdlib.h>
FILE*in;
FILE*out;
int a[101][101],s[100];
int N,A,B;
void read(int *N,int *A,int *B)
{
int x,y;
fscanf(in,"%d%d%d",N,A,B);
do
{
fscanf(in,"%d%d",&x,&y);
if(!feof(in))
a[x][y]=a[y][x]=1;
}
while(!feof(in));
}
void print(int k)
{
int i;
for(i=0; i<=k; i++)
fprintf(out,"%d ",s[i]);
fprintf(out,"\n");
}
void BKT(int k)
{
int i;
for(i=1; i<=N; i++)
{
s[k]=i;
if (pass(k))
if(s[k]==B) print(k);
else BKT(k+1);
}
}
int pass(int k)
{
int i;
for(i=0; i<k; i++)
if(s[k]==s[i]) return 0;
if(!a[s[k]][s[k-1]]) return 0;
return 1;
}
int main()
{
int N,A,B;
in=fopen("data.in","r");
out=fopen("data.out","w");
read(&N,&A,&B);
s[0]=A;
BKT(1);
return 0;
}