QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328202 | #1844. Cactus | zlt | RE | 0ms | 20336kb | C++14 | 2.5kb | 2024-02-15 18:13:16 | 2024-02-15 18:13:17 |
Judging History
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
const int maxn = 300100;
int n, m, a[maxn];
bool vis[maxn];
vector<int> G1[maxn], G2[maxn], ans;
void dfs(int u) {
vis[u] = 1;
ans.pb(u);
for (int v : G1[u]) {
a[v] ^= 1;
}
for (int v : G1[u]) {
if (!vis[v] && a[v]) {
dfs(v);
}
}
}
int dfn[maxn], low[maxn], stk[maxn], top, nt, tim;
void tarjan(int u, int fa) {
dfn[u] = low[u] = ++tim;
stk[++top] = u;
for (int v : G2[u]) {
if (v == fa) {
continue;
}
if (!dfn[v]) {
tarjan(v, u);
if (low[v] >= dfn[u]) {
++nt;
while (1) {
if (top < 0) {
exit(0);
}
int x = stk[top--];
G1[nt].pb(x);
G1[x].pb(nt);
if (x == v) {
break;
}
}
G1[nt].pb(u);
G1[u].pb(nt);
} else {
low[u] = min(low[u], low[v]);
}
} else {
low[u] = min(low[u], dfn[v]);
}
}
}
void dfs(int u, int fa) {
vis[u] = 1;
for (int v : G1[u]) {
if (v == fa) {
continue;
}
dfs(v, u);
}
if (u <= n) {
if (fa == -1) {
ans.pb(u);
}
return;
}
for (int i = 0; i < (int)G1[u].size(); ++i) {
if (G1[u][i] == fa) {
rotate(G1[u].begin(), G1[u].begin() + i, G1[u].end());
break;
}
}
for (int i = 1; i < (int)G1[u].size(); ++i) {
ans.pb(G1[u][i] + ((i & 1) ? 0 : n));
}
ans.pb(G1[u][1] + n);
ans.pb(G1[u].back() + ((G1[u].size() & 1) ? 0 : n));
}
void solve() {
scanf("%d%d", &n, &m);
while (m--) {
int u, v;
scanf("%d%d", &u, &v);
G1[u].pb(v);
G1[v].pb(u);
a[u] ^= 1;
a[v] ^= 1;
}
for (int i = 1; i <= n; ++i) {
if (a[i] && !vis[i]) {
dfs(i);
}
}
for (int u = 1; u <= n; ++u) {
for (int v : G1[u]) {
if (!vis[u] && !vis[v]) {
G2[u].pb(v);
}
}
vector<int>().swap(G1[u]);
}
nt = n;
for (int i = 1; i <= n; ++i) {
if (!dfn[i]) {
tarjan(i, -1);
}
}
ans.pb(0);
mems(vis, 0);
for (int i = 1; i <= n; ++i) {
if (!vis[i]) {
dfs(i, -1);
}
}
printf("0 %d\n", (int)ans.size());
for (int i : ans) {
if (i) {
printf("1 %d\n", i);
} else {
puts("2");
}
}
}
int main() {
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 20144kb
input:
3 3 1 2 1 3 2 3
output:
0 6 2 1 3 1 5 1 6 1 2 1 1
result:
ok You are right!
Test #2:
score: 0
Accepted
time: 0ms
memory: 20336kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 13 1 4 1 2 1 1 1 6 1 3 2 1 1 1 2 1 3 1 4 1 5 1 6 1 7
result:
ok You are right!
Test #3:
score: -100
Runtime Error
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...