-
Notifications
You must be signed in to change notification settings - Fork 0
/
1081.cpp
58 lines (45 loc) · 1.03 KB
/
1081.cpp
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
#include <bits/stdc++.h>
using namespace std;
void dfs(set<int> g[], vector<bool> &visited, int u, int space_count)
{
visited[u] = true;
for (auto v : g[u])
{
for (int i = 0; i < space_count; i++)
printf(" ");
printf("%d-%d", u, v);
if (!visited[v])
printf(" pathR(G,%d)", v);
printf("\n");
if (!visited[v])
dfs(g, visited, v, space_count + 2);
}
}
int main()
{
int n;
scanf("%d", &n);
for (int c = 1; c <= n; c++)
{
printf("Caso %d:\n", c);
int s, e;
scanf("%d%d", &s, &e);
set<int> g[s];
vector<bool> visited(s, false);
for (int i = 0; i < e; i++)
{
int u, v;
scanf("%d%d", &u, &v);
g[u].insert(v);
}
for (int u = 0; u < s; u++)
{
if (!visited[u])
{
dfs(g, visited, u, 2);
if (g[u].size() > 0)
printf("\n");
}
}
}
}