QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328216 | #1844. Cactus | Ender32k | WA | 421ms | 96504kb | C++17 | 2.8kb | 2024-02-15 18:22:53 | 2024-02-15 18:22:53 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define pb pop_back
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define ins insert
#define era erase
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef tuple<int, int, int> tu;
bool Mbe;
const int N = 3e5 + 300;
int n, m, tp, tot;
int ct[N], in[N], vs[N], st[N], bel[N], fa[N];
set<int> g[N << 1];
vector<int> t[N], c[N];
vector<pi> res;
void doit() {
queue<int> q;
for (int i = 1; i <= n; i++)
if (g[i].size() == 1) q.push(i);
while (!q.empty()) {
int u = q.front(); q.pop();
int v = *g[u].begin();
res.eb(mp(1, u));
g[v].era(u), g[u].clear();
if (g[v].size() == 1) q.push(v);
}
}
void dfs(int u, int fa) {
vs[u] = 1, st[++tp] = u, in[u] = 1;
for (int v : g[u]) {
if (!vs[v]) dfs(v, u);
else {
if (v == fa || !in[v]) continue;
tot++, c[tot].eb(v);
for (int i = tp; i && st[i] != v; i--) {
int w = st[i];
if (!bel[w]) bel[w] = tot;
c[tot].eb(w);
}
if (!bel[v]) bel[v] = tot;
}
}
in[u] = 0, tp--;
}
void dohim() {
for (int i = 1; i <= n; i++)
if (!vs[i]) dfs(i, 0);
for (int i = 1; i <= tot; i++)
for (int j : c[i]) ct[j]++;
queue<int> q;
for (int i = 1; i <= tot; i++) in[i] = 0;
for (int i = 1; i <= tot; i++)
for (int j : c[i])
if (ct[j] > 1)
if (bel[j] != i) t[fa[i] = bel[j]].eb(i), in[bel[j]]++;
for (int i = 1; i <= tot; i++)
if (!in[i]) q.push(i);
while (!q.empty()) {
int i = q.front(); q.pop();
// res.eb(mp(1, 1000 + i));
int fl = 0, sz = c[i].size();
for (int j = 1; j < sz; j++)
res.eb(mp(1, c[i][j] + fl * n)), fl ^= 1;
res.eb(mp(1, c[i][sz - 1] + fl * n));
if (sz & 1) fl ^= 1;
res.eb(mp(1, c[i][1] + fl * n));
in[fa[i]]--;
if (fa[i] && !in[fa[i]]) q.push(fa[i]);
}
}
void solve() {
cin >> n >> m;
for (int i = 1, u, v; i <= m; i++)
cin >> u >> v, g[u].ins(v), g[v].ins(u);
doit(), res.eb(mp(2, 0)), dohim();
for (int i = 1; i <= n; i++) g[i].clear();
for (auto [op, x] : res) {
if (op == 2) {
for (int i = 1; i <= n; i++)
for (int j : g[i]) g[i + n].ins(j + n);
for (int i = 1; i <= n; i++)
g[i].ins(i + n), g[i + n].ins(i);
} else {
for (int y : g[x]) g[y].era(x);
g[x].clear();
}
}
for (int i = 1; i <= n; i++)
if (g[i].size()) res.eb(mp(1, i));
cout << 0 << ' ' << res.size() << '\n';
for (auto [x, y] : res)
if (x == 1) cout << 1 << ' ' << y << '\n';
else cout << 2 << '\n';
}
bool Med;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cerr << (&Mbe - &Med) / 1048576.0 << " MB\n";
#ifdef FILE
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
int T = 1;
// cin >> T;
while (T--) solve();
cerr << (int)(1e3 * clock() / CLOCKS_PER_SEC) << " ms\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 50568kb
input:
3 3 1 2 1 3 2 3
output:
0 6 2 1 3 1 5 1 2 1 6 1 1
result:
ok You are right!
Test #2:
score: 0
Accepted
time: 11ms
memory: 51088kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 14 1 4 1 5 1 6 1 7 2 1 3 1 9 1 2 1 10 1 1 1 4 1 5 1 6 1 7
result:
ok You are right!
Test #3:
score: -100
Wrong Answer
time: 421ms
memory: 96504kb
input:
300000 368742 1 143504 1 234282 2 91276 2 296320 3 274816 4 212293 4 258214 5 253489 5 295826 6 96521 6 252745 6 267103 6 269879 7 5293 7 295586 8 44304 8 57067 8 233291 9 190526 10 18682 11 7440 12 24695 12 172561 12 243692 12 280316 13 80152 13 268749 14 146394 14 207280 15 151280 15 226848 16 458...
output:
0 424915 1 3 1 9 1 10 1 11 1 16 1 20 1 21 1 25 1 28 1 30 1 33 1 43 1 44 1 48 1 53 1 54 1 57 1 59 1 62 1 73 1 75 1 77 1 94 1 95 1 101 1 103 1 106 1 123 1 136 1 138 1 140 1 141 1 145 1 146 1 150 1 158 1 164 1 170 1 171 1 173 1 199 1 208 1 215 1 222 1 223 1 226 1 234 1 246 1 250 1 263 1 264 1 279 1 284...
result:
wrong answer The deg of 450102 is not odd.