QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328065#1844. CactuslhzawaRE 2ms21440kbC++142.1kb2024-02-15 16:44:502024-02-15 16:44:51

Judging History

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

  • [2024-02-15 16:44:51]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:21440kb
  • [2024-02-15 16:44:50]
  • 提交

answer

#include<bits/stdc++.h>
const int maxn = 3e5 + 10, maxm = 5e5 + 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();
        ! 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 19732kb

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: 2ms
memory: 21440kb

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
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...

output:


result: