-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2049C.cpp
60 lines (46 loc) · 1.23 KB
/
2049C.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int calculateMEX(const set<int> &values) {
int mex = 0;
while (values.find(mex) != values.end()) {
mex++;
}
return mex;
}
vector<int> assignValues(int size, int x, int y) {
vector<int> result(size, -1);
vector<set<int>> neighbors(size);
for (int i = 0; i < size; i++) {
neighbors[i].insert((i + 1) % size);
neighbors[i].insert((i - 1 + size) % size);
}
x--, y--;
neighbors[x].insert(y);
neighbors[y].insert(x);
for (int i = 0; i < size; i++) {
set<int> neighborValues;
for (int neighbor : neighbors[i]) {
if (result[neighbor] != -1) {
neighborValues.insert(result[neighbor]);
}
}
result[i] = calculateMEX(neighborValues);
}
return result;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, x, y;
cin >> n >> x >> y;
vector<int> values = assignValues(n, x, y);
for (int value : values) cout << value << " ";
cout << endl;
}
return 0;
}