-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1076_Desenhando_Labirintos.cpp
53 lines (42 loc) · 1.13 KB
/
1076_Desenhando_Labirintos.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
#include <iostream>
#include <queue>
#include <list>
#include <set>
#include <vector>
#define fore(i, n) for (int i = 0; i < n; i++)
using namespace std;
int dfs(int v, vector<list<int>> &grafo, vector<bool> &visitado, int soma)
{
visitado[v] = true;
soma = soma + 1;
for (list<int>::iterator it = grafo[v].begin(); it != grafo[v].end(); it++)
{
if (!visitado[*it])
{
soma = dfs(*it, grafo, visitado, soma);
soma = soma + 1;
}
}
return soma;
}
int main()
{
int x, y;
int vertice, aresta, quantidade, no_inicial, soma = 0;
cin >> quantidade;
for (int i = 0; i < quantidade; i++)
{
cin >> no_inicial >> vertice >> aresta;
vector<bool> visitados(vertice, false);
vector<list<int>> labirinto(vertice);
for (int i = 0; i < aresta; i++)
{
cin >> x >> y;
labirinto[x].push_back(y); /* Aresta x -> y */
labirinto[y].push_back(x); /* Aresta y -> x */
}
soma = dfs(no_inicial, labirinto, visitados, soma);
cout << endl;
cout << soma - 1 << endl;
}
}