QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328144 | #1844. Cactus | Ender32k | WA | 291ms | 79112kb | C++17 | 2.6kb | 2024-02-15 17:35:05 | 2024-02-15 17:35:05 |
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 d[N], ct[N], vs[N], st[N], bel[N];
set<int> g[N];
vector<int> t[N];
vector<int> 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;
for (int v : g[u]) {
if (!vs[v]) st[++tp] = u, dfs(v, u);
else {
if (v == fa || u < v) continue;
st[++tp] = u, tot++;
// cout << u << '\n';
// for (int i = 1; i <= tp; i++) cout << st[i] << ' '; cout << '\n';
while (tp && st[tp] != v) {
int w = st[tp];
if (!bel[w]) bel[w] = tot;
c[tot].eb(w), tp--;
}
c[tot].eb(v), tp--;
if (!bel[v]) bel[v] = tot;
}
}
}
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++) {
for (int j : c[i]) {
if (ct[j] > 1) {
d[i]++;
if (bel[j] != i) t[bel[j]].eb(i), t[i].eb(bel[j]);
}
}
if (d[i] <= 1) q.push(i);
}
while (!q.empty()) {
int i = q.front(); q.pop();
int fl = 0, sz = c[i].size();
for (int j = 0; j < sz - 1; j++)
res.eb(mp(1, c[i][j] + fl * n)), fl ^= 1;
res.eb(mp(1, c[i][sz - 2] + fl * n));
if (sz & 1) fl ^= 1;
res.eb(mp(1, c[i][0] + fl * n));
int flg = 0;
for (int j : t[i]) {
d[j]--;
if (!d[j]) q.push(j), flg = 1;
}
if (!flg) res.eb(mp(1, c[i][sz - 1]));
}
}
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 (auto [x, y] : res) {
if (x == 2) break;
res.eb(mp(1, y));
}
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: 33640kb
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: 4ms
memory: 33760kb
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: 291ms
memory: 79112kb
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 379436 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 43031 is not odd.