QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328279#1844. CactusHunsterWA 148ms44724kbC++143.4kb2024-02-15 18:50:482024-02-15 18:50:48

Judging History

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

  • [2024-02-15 18:50:48]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:44724kb
  • [2024-02-15 18:50:48]
  • 提交

answer

#include <bits/stdc++.h>

constexpr int N = 300005;

int n, m, cnt;
struct Edge { int x, y; };
Edge edge[N * 2];
bool del[N * 2], vis[N * 2];
std::vector<int> graph1[N];
int deg1[N];

int go(int u, int e) {
    if (u == edge[e].x) return edge[e].y;
    if (u == edge[e].y) return edge[e].x;
    assert(false);
}

std::vector<int> ans;
void work(int u) {
    ans.push_back(u);
    deg1[u] = 0;
    for (int e : graph1[u]) {
        if (del[e]) continue;
        int v = go(u, e);
        deg1[v]--;
    }
    for (int e : graph1[u]) {
        if (del[e]) continue;
        del[e] = 1;
        int v = go(u, e);
        if (deg1[v] & 1) work(v);
    }
}

int deg2[N * 2];
std::vector<int> graph2[N * 2];
int dfn[N], low[N], tot, dfs_cnt;
std::stack<int> sta;
void tarjan(int u) {
    sta.push(u);
    low[u] = dfn[u] = ++dfs_cnt;
    for (int e : graph1[u]) {
        if (del[e]) continue;
        if (vis[e]) continue;
        vis[e] = 1;
        int v = go(u, e);
        if (!dfn[v]) {
            tarjan(v);
            low[u] = std::min(low[u], low[v]);
            if (low[v] >= dfn[u]) {
                tot++;
                int x;
                do {
                    x = sta.top();
                    sta.pop();
                    deg2[x]++;
                    deg2[tot]++;
                    graph2[x].push_back(tot);
                    graph2[tot].push_back(x);
                }
                while (x != v);
                deg2[u]++;
                deg2[tot]++;
                graph2[u].push_back(tot);
                graph2[tot].push_back(u);
            }
        }
        else low[u] = std::min(low[u], dfn[v]);
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        edge[++cnt] = {x, y};
        graph1[x].push_back(cnt);
        graph1[y].push_back(cnt);
        deg1[x]++;
        deg1[y]++;
    }
    for (int i = 1; i <= n; i++) if (deg1[i] & 1) work(i);
    // for (int i = 1; i <= n; i++) assert(~deg1[i] & 1);
    if (n >= 10000) {
        return 0;
    }
    ans.push_back(-1);
    tot = n;
    for (int i = 1; i <= n; i++) {
        if (deg1[i]) {
            if (!dfn[i]) tarjan(i);
        }
        else ans.push_back(i);
    }
    std::queue<int> que;
    for (int i = 1; i <= tot; i++) if (deg2[i] == 1) que.push(i);
    while (que.size()) {
        int u = que.front();
        que.pop();
        if (u > n) {
            int p = -1;
            for (int i = 0; i < graph2[u].size(); i++)
                if (deg2[graph2[u][i]] > 1) 
                    p = i;
            std::vector<int> cur;
            if (p >= 0) {
                for (int i = p; i < graph2[u].size(); i++) cur.push_back(graph2[u][i]);
                for (int i = 0; i < p; i++) cur.push_back(graph2[u][i]);
            }
            else cur = graph2[u];
            for (int i = 1; i < cur.size(); i++) ans.push_back(cur[i] + (i & 1) * n);
            ans.push_back(cur[1]);
            ans.push_back(cur.back() + (cur.size() & 1) * n);
            if (p == -1) ans.push_back(cur[0]);
        }
        for (int v : graph2[u]) 
            if (--deg2[v] == 1)
                que.push(v);
    }
    printf("%d %lu\n", 0, ans.size());
    for (int x : ans) {
        if (x < 0) puts("2");
        else printf("1 %d\n", x);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 32468kb

input:

3 3
1 2
1 3
2 3

output:

0 6
2
1 5
1 1
1 2
1 4
1 3

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 4ms
memory: 32780kb

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
Wrong Answer
time: 148ms
memory: 44724kb

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:

wrong output format Unexpected end of file - int32 expected