import java.io.*;
public class cal
{
public static String glo_path="";
public static int value[][]={
//权矩阵
{0,1,1,0,0},
{0,0,0,1,0},
{0,0,0,1,0},
{1,0,0,0,1},
{0,0,0,1,0}
};
public static int flags[]={0,0,0,0,0};
public static int cal(int start,int end ,String t_path)
{
System.out.println("aaa");
String path=t_path;
for(int i=0;i<5;i++)
{
if(value[start][i]==0)
{
continue;
}
else
{
if(i==end)
{
path+=i;
glo_path=glo_path+path+",";
return 1;
}
else if(flags[i]==0)
{
path+=i;
flags[i]=1;
int ret=cal(i,end,path);
if(ret==1 || ret==0)
{
String p="";
for(int j=0;j<path.length()-1;j++)
{
p+=path.charAt(j);
flags[i]=0;
}
path=p;
};
}
}
}
return 0;
}
public static void main(String args[])
{
//比方给定 0 3 求可达路径
cal(0,3,"0 ");
System.out.println(glo_path);
}
}
public class cal
{
public static String glo_path="";
public static int value[][]={
//权矩阵
{0,1,1,0,0},
{0,0,0,1,0},
{0,0,0,1,0},
{1,0,0,0,1},
{0,0,0,1,0}
};
public static int flags[]={0,0,0,0,0};
public static int cal(int start,int end ,String t_path)
{
System.out.println("aaa");
String path=t_path;
for(int i=0;i<5;i++)
{
if(value[start][i]==0)
{
continue;
}
else
{
if(i==end)
{
path+=i;
glo_path=glo_path+path+",";
return 1;
}
else if(flags[i]==0)
{
path+=i;
flags[i]=1;
int ret=cal(i,end,path);
if(ret==1 || ret==0)
{
String p="";
for(int j=0;j<path.length()-1;j++)
{
p+=path.charAt(j);
flags[i]=0;
}
path=p;
};
}
}
}
return 0;
}
public static void main(String args[])
{
//比方给定 0 3 求可达路径
cal(0,3,"0 ");
System.out.println(glo_path);
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/2f60c0bc47d4178ac5e2b807936153ff.gif)