-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path459.cpp
More file actions
47 lines (46 loc) · 1.1 KB
/
459.cpp
File metadata and controls
47 lines (46 loc) · 1.1 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
#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
queue<int> q;
char ch[10];
int tc;
int t = 1, i, j, k, l, m, n;
cin >> tc;
getchar();
getchar();
while (tc--) {
memset(a, 0, sizeof(a));
gets(ch);
l = ch[0] - 'A';
for (i = 0; i <= l; i++) a[i][i] = 1;
while (gets(ch)) {
if (strlen(ch) == 0) break;
n = ch[0] - 'A';
m = ch[1] - 'A';
a[n][m] = 1;
a[m][n] = 1;
}
int count = 0;
for (j = 0; j <= l; j++) {
q.push(j);
int flag = 0;
while (!q.empty()) {
int p = q.front();
q.pop();
for (i = 0; i <= l; i++)
if (a[p][i] == 1) {
q.push(i);
a[p][i] = 0;
a[i][p] = 0;
flag = 1;
}
}
if (flag == 1) count++;
}
if (t != 1) puts("");
t++;
printf("%d\n", count);
}
return 0;
}