-
Notifications
You must be signed in to change notification settings - Fork 3
/
D.cpp
80 lines (71 loc) · 1.73 KB
/
D.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
if (n % 2 == 0){
cout << "First" << endl;
for(int i = 1; i <= n; i++){
cout << i << ' ';
}
for(int i = 1; i <= n; i++){
cout << i << ' ';
}
cout << endl;
int t;
cin >> t;
return 0;
}
cout << "Second" << endl;
vector<vector<int> > pos(n + 1);
for(int i = 1; i <= 2 * n; i++){
int x;
cin >> x;
pos[x].push_back(i);
}
vector<vector<int> > g(2 * n + 1);
for(int i = 1; i <= n; i++){
g[i].push_back(i + n);
g[i + n].push_back(i);
g[pos[i][0]].push_back(pos[i][1]);
g[pos[i][1]].push_back(pos[i][0]);
}
vector<int> c(2 * n + 1, -1);
auto dfs = [&](auto &&dfs, int u, int color) -> void {
c[u] = color;
for(auto j : g[u]){
if (c[j] != -1) continue;
dfs(dfs, j, color ^ 1);
}
};
for(int i = 1; i <= 2 * n; i++){
if (c[i] == -1){
dfs(dfs, i, 0);
}
}
LL sum[2]{};
vector<int> ans[2];
for(int i = 1; i <= 2 * n; i++){
ans[c[i]].push_back(i);
sum[c[i]] += i;
}
for(int i = 0; i < 2; i++){
if (sum[i] % (2 * n) == 0){
for(auto x : ans[i]){
cout << x << ' ';
}
cout << endl;
int t;
cin >> t;
return 0;
}
}
}