QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328070#1844. CactuslhzawaWA 217ms54452kbC++142.1kb2024-02-15 16:46:212024-02-15 16:46:21

Judging History

你现在查看的是最新测评结果

  • [2024-02-15 16:46:21]
  • 评测
  • 测评结果:WA
  • 用时:217ms
  • 内存:54452kb
  • [2024-02-15 16:46:21]
  • 提交

answer

#include<bits/stdc++.h>
const int maxn = 3e5 + 10, maxN = maxn * 2;
int n, m, N;
std::vector<int> qr;
std::vector<int> G[maxn], E[maxN];
bool vis[maxn];
int deg[maxn];
int dfn[maxn], low[maxn], stk[maxn], top, dt;
void dfs(int u) {
    dfn[u] = low[u] = ++dt, stk[++top] = u;
    for (int v : G[u]) {
        if (vis[v]) continue;
        if (! dfn[v]) {
            dfs(v);
            low[u] = std::min(low[u], low[v]);
            if (dfn[u] == low[v]) {
                N++;
                for (int t = 0; t != v; ) {
                    t = stk[top--];
                    E[t].push_back(N), E[N].push_back(t);
                }
                E[u].push_back(N), E[N].push_back(u);
            }
        } else low[u] = std::min(low[u], dfn[v]);
    }
}
void solve(int u, int fa) {
    for (int v : E[u]) v != fa && (solve(v, u), 1);
    if (u > n) {
        std::vector<int> P;
        for (int i = 0, cnt = 0; cnt < 2; cnt += E[u][i] == fa, (++i) %= E[u].size())
            cnt == 1 && E[u][i] != fa && (P.push_back(E[u][i]), 1);
        int op = 0;
        for (int v : P) qr.push_back(v + op * n), op ^= 1;
        qr.push_back(P.front() + n), qr.push_back(P.back() + op * n);
    }
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int x, y; scanf("%d%d", &x, &y);
        G[x].push_back(y), G[y].push_back(x);
        deg[x]++, deg[y]++;
    }
    std::vector<int> q1;
    std::queue<int> q;
    for (int i = 1; i <= n; i++) deg[i] <= 1 && (q.push(i), 1);
    while (! q.empty()) {
        int u = q.front(); q.pop();
        assert(u != 140183);
        ! vis[u] && (q1.push_back(u), vis[u] = 1);
        if (! deg[u]) continue;
        qr.push_back(u);
        deg[u]--;
        for (int v : G[u]) if (deg[v]) (--deg[v]) <= 1 && (q.push(v), 1);
    }
    qr.push_back(0);
    for (int x : q1) qr.push_back(x);
    N = n;
    for (int i = 1; i <= n; i++) {
        if (vis[i] || dfn[i]) continue;
        top = 0, dfs(i);
        solve(i, 0);
        qr.push_back(i);
    }
    printf("0 %zu\n", qr.size());
    for (int x : qr) ! x ? puts("2") : printf("1 %d\n", x);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 25176kb

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: 3ms
memory: 24892kb

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 4
1 5
1 6
1 7
1 3
1 9
1 10
1 2
1 1

result:

ok You are right!

Test #3:

score: -100
Wrong Answer
time: 217ms
memory: 54452kb

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 503143
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 140183 is not odd.