#include<stdio.h>
#include <stdlib.h>
#include <string.h>//我这里的头以及尾巴与书上的不一样。
typedef struct ArcNode
{
int from, to;
struct ArcNode * fnext, *tonext;
int w;
}ArcNode;
typedef struct VertexNode
{
char info;
ArcNode *ff, *ft;
}VertexNode;
typedef struct Graph
{
int num_vertex;
int num_arc;
VertexNode *ver;
}Graph;
Graph *Create(int n)
{
Graph * G = (Graph*)malloc(sizeof(Graph));
G->num_vertex = n;
G->num_arc = 0;
G->ver = (VertexNode*)calloc(n+1, sizeof(VertexNode));
for(int i = 1; i <= n; i++)
{
G->ver[i].ff = NULL;
G->ver[i].ft = NULL;//在这里可以补加点的信息
}
return G;
}
void AddArc(Graph *G,int a, int b, int c)
{
(G->num_arc)++;
ArcNode *s = (ArcNode*)malloc(sizeof(ArcNode));
s->from = a;
s->to = b;
s->fnext = G->ver[a].ff;
G->ver[a].ff = s;
s->tonext = G->ver[b].ft;
G->ver[b].ft = s;
s->w = c;
}
//深度优先查找最短路
void Print(int *pre,int x)
{
int buf[1000];
int cnt = 0;
while(pre[x] != -1)
{
cnt++;
buf[cnt] = x;
x = pre[x];
}
for(int j = cnt; j >0; j--)
{
printf("%d ",buf[j]);
}
}
int DFS(Graph *G,int *pre, int x, int y)
{
for(ArcNode* j = G->ver[x].ff;j; j = j->fnext)
{
if(pre[j->to]==-1)
{
pre[j->to] = x;
if(j->to == y)
{
Print(pre, y);
return 1;
}
if(DFS(G, pre, j->to, y)) return 1;//很经典:这样可以在找到的时候快速的退出所有的递归调用。
}
}
return 0;
}
void simple_track(Graph *G, int x, int y)
{
int *pre = (int*)calloc(sizeof(G->num_vertex)+1, sizeof(int));
for(int i = 1; i <= G->num_vertex; i++)
pre[i] = -1;
if(!DFS(G, pre, x, y))
{
printf("disabled!");
}
//free(pre);
}
int main()
{
int n,m;
scanf("%d",&n);
Graph *G = Create(n);
scanf("%d",&m);
for(int i = 1; i <= m; i++)
{
int a, b;
scanf("%d%d",&a, &b);
AddArc(G,a,b,0);
}
int x, y;
scanf("%d%d",&x, &y);
simple_track(G, x, y);
return 0;
}
/*
6 5
1 2
2 6
2 3
2 4
4 5
1 5
*/