-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1082.cpp
More file actions
70 lines (63 loc) · 1.43 KB
/
1082.cpp
File metadata and controls
70 lines (63 loc) · 1.43 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
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#define maxV 10000
#define Vertex int
using namespace std;
int cnt, lbl[maxV];
int V, A, adj[100][100];
int achou,segmentos;
void pathR (Vertex v) {
Vertex w;
lbl[v] = cnt++; ///adaptado
for (w = 0; w < V; w++) {
if (adj[v][w] == 1) {
achou =1;
if (lbl[w] == -1) {
pathR(w);
}
}
}
}
void DIGRAPHpath (void) {
Vertex v;
for (v = 0; v < V; v++) {
lbl[v] = -1;
}
for (v = 0; v < V; v++) {
if (lbl[v] == -1) {
cout << endl ;
segmentos++;
cnt = 1;
pathR(v);
for (int i = 0; i < V; i++) {
if (lbl[i] > 0) {
cout << char ('a'+i) <<",";
lbl[i]=0;
}
}
}
}
}
int main(void) {
char orig,dest;
int casos;
cin >> casos;
for(int i = 0; i < casos; i++) {
cin >> V; ///Vertices
for (int j=0; j<V; j++) {
for (int k=0; k<V; k++) {
adj[j][k]=0;
}
}
cin >> A; ///Arestas
for (int j=0; j<A; j++) {
cin >> orig >> dest;
adj[orig-'a'][dest-'a']++;
adj[dest-'a'][orig-'a']++;
}
segmentos=0;
cout << "Case #" << (i+1) << ":";
DIGRAPHpath ();
cout <<endl<<segmentos<<" connected components\n\n";
}
return(0);
}