-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdogeforces.cpp
73 lines (60 loc) · 1.67 KB
/
dogeforces.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
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;
using pi = pair<int, int>;
int main() {
int n;
cin >> n;
set<int, greater<int>> lca[maxn];
map<int, int> first_n;
map<int, int> first_n_inv;
int best = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int v;
cin >> v;
if (i == j) {
first_n[i + 1] = v;
first_n_inv[v] = i + 1;
}
best = max(best, v);
lca[i].insert(v);
}
}
map<vector<pi>, vector<pi>> par;
for (int i = 0; i < n; i++) {
set<int, greater<int>> curr_set = lca[i];
int curr_depth = 0;
vector<pi> last = {};
for(int l : curr_set) {
last.push_back({l, curr_depth++});
}
while(last.size() > 0) {
vector<pi> temp = last;
for (pi th : last) cout << th.first << " ";
last.pop_back();
cout << endl;
par[temp] = last;
}
}
map<vector<pi>, int> ind;
int i = 0;
cout << par.size() + 1 << endl;
for (auto thing : par) {
vector<pi> node = thing.first;
for (pi th : node) cout << th.first << " ";
cout << endl;
if (node.size() < 1) continue;
ind[node] = i;
cout << node.back().first << " ";
}
cout << best << endl;
cout << par.size() + 1 << endl;
for (auto node : par) {
if (node.first.size() < 1) continue;
int c = ind[node.first];
int p = node.second.front().first == best ? par.size() + 1 : ind[node.second];
cout << c << " " << p << endl;
}
return 0;
}