-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuilding Teams.cpp
More file actions
executable file
·60 lines (55 loc) · 908 Bytes
/
Copy pathBuilding Teams.cpp
File metadata and controls
executable file
·60 lines (55 loc) · 908 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
58
59
60
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n, m;
vector<int> v[200009];
int odw[200009];
int kol[200009];
queue<int> q;
bool bfs(int start) {
q.push(start);
odw[start] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto it : v[x]) {
if (odw[it] == 0) {
odw[it] = odw[x] ^ 3;
q.push(it);
} else if (odw[it] == odw[x]) {
return false;
}
}
}
return true;
}
bool bfs_run() {
for (int i = 1; i <= n; i++) {
if (odw[i] == 0) {
bool ok = bfs(i);
if (ok == false) {
return ok;
}
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
if (bfs_run()) {
for (int i = 1; i <= n; i++) {
cout << odw[i] << " ";
}
cout << "\n";
} else {
cout << "IMPOSSIBLE\n";
}
return 0;
}