-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3364-fields_division.cpp
More file actions
57 lines (42 loc) · 862 Bytes
/
3364-fields_division.cpp
File metadata and controls
57 lines (42 loc) · 862 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int N, M;
short result[3 * 100001];
void solve() {
memset(result, -1, sizeof result);
vector<vector<int>> graph(N);
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
graph[u].push_back(v);
graph[v].push_back(u);
}
result[N - 1] = 0;
result[N - 2] = 1;
queue<int> q;
q.push(N - 2);
while (!q.empty()) {
const int u = q.front();
q.pop();
for (const int v : graph[u]) {
if (~result[v]) continue;
result[v] = result[u];
q.push(v);
}
}
for (int i = 0; i < N; i++) {
if (~result[i]) continue;
result[i] = 0;
}
for (int i = 0; i < N; i++) {
cout << (result[i] ? 'B' : 'A');
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
while (cin >> N >> M) solve();
}