QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328250 | #1844. Cactus | Ender32k | WA | 570ms | 94920kb | C++17 | 3.0kb | 2024-02-15 18:35:01 | 2024-02-15 18:35:02 |
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;
const int M = 5e5 + 500;
int n, m, tp, tot;
int ct[N], in[N], vs[N], st[N], bel[N], fa[N];
pi e[M];
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();
if (g[u].size() & 1 ^ 1) continue;
res.eb(mp(1, u));
for (int v : g[u]) {
g[v].era(u);
if (g[v].size() & 1) q.push(v);
}
g[u].clear();
}
}
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), e[i] = mp(u, v);
doit(), res.eb(mp(2, 0)), dohim();
for (int i = 1; i <= n; i++) g[i].clear();
for (int i = 1; i <= m; i++) {
auto [u, v] = e[i];
g[u].ins(v), g[v].ins(u);
}
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: 4ms
memory: 46168kb
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: 10ms
memory: 46344kb
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: 570ms
memory: 94920kb
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 523985 1 3 1 8 1 9 1 10 1 11 1 16 1 20 1 21 1 25 1 28 1 29 1 30 1 32 1 33 1 34 1 41 1 42 1 43 1 44 1 47 1 48 1 53 1 54 1 55 1 57 1 59 1 62 1 65 1 73 1 75 1 77 1 80 1 81 1 87 1 88 1 94 1 95 1 101 1 102 1 103 1 106 1 112 1 123 1 128 1 129 1 133 1 136 1 137 1 138 1 140 1 141 1 143 1 145 1 146 1 150 1...
result:
wrong answer The deg of 262566 is not odd.