-
Notifications
You must be signed in to change notification settings - Fork 48
/
1081.c
91 lines (64 loc) · 1.38 KB
/
1081.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
@autor: Malbolge;
@data: 20/09/2019;
@nome: DFSr - Hierarquia de Profundidade;
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define true 1
#define false 0
#define MAXSIZE 30
int v, j;
_Bool flag;
int tmp[MAXSIZE];
char esp[MAXSIZE];
_Bool vis[MAXSIZE];
int adj[MAXSIZE][MAXSIZE];
void dfs(int);
int main(int argc, char **argv)
{
int u, w;
int n, e, i, caso = 0;
scanf("%d", &n);
while (n--)
{
scanf("%d %d", &v, &e);
memset(vis, 0, sizeof(vis));
memset(adj, 0, sizeof(adj));
for (i = 0; i < e; ++i)
scanf("%d %d", &u, &w), adj[u][w] = true;
printf("Caso %d:\n", ++caso);
for (i = 0; i < v; ++i)
{
esp[0] = 0;
flag = false;
if (!vis[i])
dfs(i);
if (flag)
putchar_unlocked('\n');
}
}
return 0;
}
void dfs(int u)
{
int i;
vis[u] = true;
strcat(esp, " ");
for (i = 0; i < v; ++i)
{
if (adj[u][i])
{
flag = true;
if (!vis[i])
{
printf("%s%d-%d pathR(G,%d)\n", esp, u, i, i);
dfs(i);
esp[strlen(esp) - 2] = 0;
}
else
printf("%s%d-%d\n", esp, u, i);
}
}
}