Adjacency Matrix Storage Simple Path (swust OJ 1070)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.