QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#131748 | #2760. Simurgh | pandapythoner# | Compile Error | / | / | C++20 | 6.3kb | 2023-07-27 23:04:12 | 2024-07-04 01:00:57 |
Judging History
你现在查看的是最新测评结果
- [2024-07-04 01:00:57]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-07-27 23:04:12]
- 提交
answer
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#else
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#endif
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll inf = 1e18;
mt19937 rnd(234);
struct DSU {
int n;
vector<int> t;
int cmps = 0;
void build(int _n) {
n = _n;
t.resize(n);
for (int i = 0; i < n; i += 1) {
t[i] = i;
}
cmps = n;
}
int get(int v) {
if (t[v] == v) {
return v;
}
return (t[v] = get(t[v]));
}
void merge(int a, int b) {
a = get(a);
b = get(b);
if (a == b) {
return;
}
cmps -= 1;
t[a] = b;
}
int get_cmps() {
return cmps;
}
};
struct edge {
int to, i;
};
bool operator==(const edge &a, const edge &b) {
return a.to == b.to && a.i == b.i;
}
int n, m;
vector<pair<int, int>> edgs;
vector<int> tp;
vector<vector<edge>> g;
vector<int> usd;
vector<int> h;
DSU dsu;
bool dfs0(int v, int mh, int pri, vector<int> &stck, vector<int> &cycle) {
h[v] = mh;
usd[v] = 1;
for (auto [to, i] : g[v]) {
if (pri == i) {
continue;
}
if (usd[to] == 1) {
int dst = mh - h[to];
cycle = vector<int>(stck.end() - dst, stck.end());
cycle.push_back(i);
return true;
}
if (usd[to] == 0) {
stck.push_back(i);
int x = dfs0(to, mh + 1, i, stck, cycle);
stck.pop_back();
if (x) {
return true;
}
}
}
usd[v] = 2;
return false;
}
void find_cycle(vector<int> &cycle) {
usd.assign(n, 0);
h.resize(n);
vector<int> stck;
stck.reserve(n);
int v0 = rnd() % n;
dfs0(v0, 0, -1, stck, cycle);
}
void dfs1(int v, vector<int> &rs) {
usd[v] = 1;
for (auto [to, i] : g[v]) {
if (!usd[to]) {
rs.push_back(i);
dfs1(to, rs);
}
}
}
vector<int> add_edgs(vector<int> &c) {
auto rs = c;
usd.assign(n, 0);
for (auto i : c) {
auto [u, v] = edgs[i];
usd[u] = 1;
usd[v] = 1;
}
for (auto i : c) {
auto [u, v] = edgs[i];
if (usd[u] == 1) {
dfs1(u, rs);
usd[u] = 2;
}
if (usd[v] == 1) {
dfs1(v, rs);
usd[v] = 2;
}
}
return rs;
}
void reveal_cycle(vector<int> &c) {
auto f = add_edgs(c);
int sz = (int)c.size();
vector<int> p(sz, -1);
int mx = 0;
for (int i = 0; i < sz; i += 1) {
int j = c[i];
if (tp[j] == -1) {
auto nf = f;
nf.erase(nf.begin() + i);
p[i] = count_common_roads(nf);
mx = max(mx, p[i]);
}
}
for (int i = 0; i < sz; i += 1) {
int j = c[i];
if (tp[j] == -1) {
if (p[i] == mx) {
tp[j] = 0;
} else {
tp[j] = 1;
}
}
}
}
void erase(vector<edge> &t, const edge &x) {
for (int i = 0; i < (int)t.size(); i += 1) {
if (t[i] == x) {
t.erase(t.begin() + i);
break;
}
}
}
void delete_edge_from_g(int i) {
auto [u, v] = edgs[i];
erase(g[u], edge{v, i});
erase(g[v], edge{u, i});
}
vector<int> tr;
int count_gd_edgs(vector<int> p) {
if (p.empty()) {
return 0;
}
DSU mdsu;
mdsu.build(n);
for (auto i : p) {
auto [u, v] = edgs[i];
mdsu.merge(u, v);
}
auto f = p;
int rs = 0;
for (auto i : tr) {
auto [u, v] = edgs[i];
if (mdsu.get(u) != mdsu.get(v)) {
mdsu.merge(u, v);
f.push_back(i);
if (tp[i] == 1) {
rs -= 1;
}
}
}
rs += count_common_roads(f);
return rs;
}
void reveal_edgs(int tl, int tr, vector<int> p) {
int x = count_gd_edgs(vector<int>(p.begin() + tl, p.begin() + tr + 1));
if (x == 0) {
for (int j = tl; j <= tr; j += 1) {
int i = p[j];
tp[i] = 0;
}
return;
}
if (tl == tr) {
int i = p[tl];
tp[i] = 1;
return;
}
int tm = (tl + tr) / 2;
reveal_edgs(tl, tm, p);
reveal_edgs(tm + 1, tr, p);
}
vector<int> solve_slow() {
if (m == n - 1) {
vector<int> rs(n - 1);
for (int i = 0; i < n - 1; i += 1) {
rs[i] = i;
}
return rs;
}
dsu.build(n);
tp.assign(m, -1);
g.assign(n, vector<edge>());
for (int i = 0; i < m; i += 1) {
auto [u, v] = edgs[i];
g[u].push_back(edge{v, i});
g[v].push_back(edge{u, i});
}
// int cnt = m;
while (dsu.get_cmps() > 1) {
vector<int> c;
find_cycle(c);
reveal_cycle(c);
for (auto j : c) {
auto [u, v] = edgs[j];
dsu.merge(u, v);
if (tp[j] == 0) {
delete_edge_from_g(j);
}
}
}
tr.clear();
for (int i = 0; i < m; i += 1) {
if (tp[i] != -1) {
tr.push_back(i);
}
}
while (1) {
vector<int> p;
DSU mdsu;
mdsu.build(n);
for (int i = 0; i < m; i += 1) {
if (tp[i] == -1) {
auto [u, v] = edgs[i];
if (mdsu.get(u) != mdsu.get(v)) {
mdsu.merge(u, v);
p.push_back(i);
}
}
}
if (p.empty()) {
break;
}
reveal_edgs(0, (int)p.size() - 1, p);
}
vector<int> rs;
for (int i = 0; i < m; i += 1) {
if (tp[i] == 1) {
rs.push_back(i);
}
}
return rs;
}
vector<int> find_roads(int _n, vector<int> _u, vector<int> _v) {
n = _n;
m = _u.size();
edgs.resize(m);
for (int i = 0; i < m; i += 1) {
edgs[i] = make_pair(_u[i], _v[i]);
}
auto rs = solve_slow();
return rs;
}
詳細信息
In file included from /usr/include/c++/13/string:43, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52, from answer.code:8: /usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int> > >::_Vector_impl::~_Vector_impl()’: /usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::pair<int, int>]’: target specific option mismatch 184 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/13/vector:66, from /usr/include/c++/13/functional:64, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53: /usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here 133 | struct _Vector_impl | ^~~~~~~~~~~~