-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1076.cpp
More file actions
58 lines (50 loc) · 1.09 KB
/
1076.cpp
File metadata and controls
58 lines (50 loc) · 1.09 KB
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 <iostream>
#define maxV 100
#define Vertex int
using namespace std;
int cnt, lbl[maxV];
int V,A, adj[100][100];
string espacos="";
int entrou = 0;
int conta=0;
void pathR (Vertex v) {
Vertex w;
lbl[v] = cnt++;
for (w = 0; w < V; w++) {
if (adj[v][w] == 1) {
if (lbl[w] == -1) { /// se nao percorreu ainda
conta++;
pathR(w);
}
}
}
}
int main(void) {
int orig,dest,saida,n;
cin >> n;;
while(n--) {
conta = 0;
Vertex v;
cin >> saida; /// Origem
cin >> V; ///Vertices
/// Zera a Matriz de Adjacência
for (int i=0; i<V; i++) {
for (int j=0; j<V; j++) {
adj[i][j]=0;
}
}
cin >> A; ///Arestas
for (int i=0; i<A; i++) {
cin >> orig >> dest;
adj[orig][dest]=1;
adj[dest][orig]=1;
}
for (v = 0; v < V; v++) {
lbl[v] = -1;
}
cnt = 0;
pathR (saida);
cout << conta * 2 << endl;
}
return(0);
}