#include "meetings.h"
#include <algorithm>
#include <map>
#include <numeric>
#include <vector>
using namespace std;
void bridge(int a, int b) { if (a>b) swap(a, b); Bridge(a, b); }
void work_set(vector<int> &v) {
if (v.size() == 1u) return;
int a = v[0], b = v[1], n = v.size();
map<int, vector<int>> roots;
roots[a]; roots[b];
for (int i=2; i<n; ++i) roots[Query(a, b, v[i])].push_back(v[i]);
for (auto &tmp : roots) {
if (tmp.first == a || tmp.first == b) tmp.second.push_back(tmp.first);
work_set(tmp.second);
}
n = roots.size();
vector<int> foots; foots.reserve(n);
for (auto &tmp : roots) if (tmp.first != a && tmp.first != b) foots.push_back(tmp.first);
if (foots.empty()) { bridge(a, b); return; }
roots = move(decltype(roots)());
sort(foots.begin(), foots.end(), [&](const int& x, const int& y) {
return Query(x, y, a) == a;
});
bridge(a, foots[0]);
for (int i=1; i<n; ++i) bridge(foots[i-1], foots[i]);
bridge(foots[n-1], b);
}
void Solve(int N) {
vector<int> v(N);
iota(v.begin(), v.end(), 0);
work_set(v);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
500 KB |
Wrong Answer [4] |
2 |
Halted |
0 ms |
0 KB |
- |