Description
Assuming that the graph G is stored with adjacency matrix, an algorithm is designed to output all the simple paths from the vertex u to V in Figure G.
Input
A simple path is a vertex that is not duplicated on a path.First Act OneIntegerNThat represents the number of vertices(VertexNumber is0 to n-1< Span style= "font-family: the song Body;" >) u and v< Span style= "font-family: the song Body;" > The number, Next is a n*n0 means no adjacency, means no adjacency.
Output
Outputs all the simple paths from vertex u to V in Figure G.
Sample Input
5
0 3
0 1 0) 1 1
1 0 1) 1 0
0 1 0) 1 1
1 1 1) 0 1
1 0 1) 1 0
Sample Output01230124301303042130423043 PE Code: (School OJ a little water, the format key value does not understand)
#include <stdio.h>#include<string.h>intmap[1100][1100];//Save MapintPoint ;structA//record the current location{ intNow ;} q[10000];intStart,end;//Starting Pointintvis[10000];//MarkvoidPrintintH//Print function{ for(intI=0; i<=h;i++) printf ("%d", Q[i].now); printf ("\ n");}voidDFS (intX//Deep Search{ if(q[x].now==end) {print (x); return; } for(intI=0; i<point;i++) if(map[i][q[x].now]==1&&vis[i]==0) {q[x+1].now=i; Vis[i]=1;//MarkDFS (x+1); Vis[i]=0;//Mark Release }}intMain () {scanf ("%d",&Point ); scanf ("%d%d",&start,&end); for(intI=0; i<point;i++) for(intj=0; j<point;j++) scanf ("%d",&map[i][j]);//Q[0].front=-1;vis[0]=1; q[0].now=start; DFS (0); return 0;}/*1 0 1 0 1 1 xx 1 0 1 1 1 1 1 0 each 0 1 1 0*/+
Adjacency Matrix Storage Simple Path (swust OJ 1070)