이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "meetings.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
void read(T &x)
{
x = 0;
register int c;
while ((c = getchar()) && (c > '9' || c < '0'))
;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
}
constexpr bool typetest = 0;
constexpr int N = 2e3 + 5;
//Ảo thật đấy
int lcam[N][N];
int LCA(int u, int v)
{
if (u == v)
return u;
if (u == 0 || v == 0)
return 0;
if (lcam[u][v] != -1)
return lcam[u][v];
return (lcam[u][v] = lcam[v][u] = Query(0, u, v));
}
void Recursive(int root, vector<int> &s)
{
if (s.size() == 1)
return;
if (s.size() == 2)
{
Bridge(min(s[0], s[1]), max(s[0], s[1]));
return;
}
map<int, vector<int>> subtree;
int u;
do
{
u = s[rand() % s.size()];
} while (u == root);
vector<int> chain;
for (auto i : s)
{
int lca = LCA(i, u);
if (lca == i)
chain.emplace_back(i);
subtree[lca].emplace_back(i);
}
sort(chain.begin(), chain.end(), [&](const int &x, const int &y)
{ return LCA(x, y) == x; });
for (int i = 0; i < (int)chain.size() - 1; ++i)
Bridge(min(chain[i], chain[i + 1]), max(chain[i], chain[i + 1]));
for (auto i : subtree)
Recursive(i.first, i.second);
}
void Solve(int n)
{
memset(lcam, -1, sizeof lcam);
vector<int> s;
for (int i = 0; i < n; ++i)
s.emplace_back(i);
random_shuffle(s.begin(), s.end());
Recursive(0, s);
}
/*
void Read()
{
}
void Solve()
{
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("xor.INP", "r"))
{
freopen("xor.inp", "r", stdin);
freopen("xor.out", "w", stdout);
}
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
// cout << "Case #" << _ << ": ";
Read();
Solve();
}
// cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
*/
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'void read(T&)':
meetings.cpp:13:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
13 | register int c;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |