QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#328245 | #1844. Cactus | Ender32k | WA | 392ms | 153836kb | C++17 | 3.1kb | 2024-02-15 18:31:24 | 2024-02-15 18:31:25 |
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()) continue;
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), 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 {
if (g[x].size() % 2 == 0) return cout << -1 << '\n', void();
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 49048kb
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: 0ms
memory: 49660kb
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: 392ms
memory: 153836kb
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:
-1
result:
wrong answer Integer parameter [name=m'] equals to -1, violates the range [0, 0]