-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccc01s3.cpp
46 lines (42 loc) · 1.05 KB
/
ccc01s3.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
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool>> adj(27, vector<bool>(27));
vector<bool> vis(27);
bool BFS()
{
fill(vis.begin(), vis.end(), false);
queue<int> buf;
buf.push(0);
while (!buf.empty())
{
int u = buf.front();
if (u == 1) return false;
buf.pop();
for (int x = 0; x < 27; x++)
if (adj[u][x] && !vis[x])
buf.push(x), vis[x] = true;
}
return true;
}
int main()
{
char a, b;
vector<pair<char,char>> ed;
scanf(" %c %c", &a, &b);
while (a != '*' && b != '*')
{
ed.push_back({a, b});
adj[a-'A'][b-'A'] = adj[b-'A'][a-'A'] = true;
scanf(" %c %c", &a, &b);
}
int c = 0;
for (auto &x : ed)
{
adj[x.first-'A'][x.second-'A'] = adj[x.second-'A'][x.first-'A'] = false;
if (BFS())
printf("%c%c\n", x.first, x.second), c++;
adj[x.first-'A'][x.second-'A'] = adj[x.second-'A'][x.first-'A'] = true;
}
printf("There are %i disconnecting roads.", c);
return 0;
}