QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327987#1844. Cactusc20230201WA 115ms46876kbC++142.0kb2024-02-15 15:55:282024-02-15 15:55:28

Judging History

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

  • [2024-02-15 15:55:28]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:46876kb
  • [2024-02-15 15:55:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int maxn=1e6+5;

int vs, tot, cnt=1, n, m;
int fir[maxn], ver[maxn], nxt[maxn], dfn[maxn], low[maxn], deg[maxn], broken[maxn];
vector<int> sta, lp[maxn], ans;

void add(int u,int v) {
    ver[++cnt]=v, nxt[cnt]=fir[u], fir[u]=cnt;
    ver[++cnt]=u, nxt[cnt]=fir[v], fir[v]=cnt;
    return ;
}

void dfs(int x) {
    deg[x]=0;
    ans.push_back(x);
    for(int i=fir[x];i;i=nxt[i]) {
        if(broken[i]) continue;
        broken[i]=broken[i^1]=1;
        int y=ver[i]; deg[y]--;
    }
    for(int i=fir[x];i;i=nxt[i]) {
        int y=ver[i];
        if(deg[y]&1) dfs(y);
    }
    return ;
}

void dfs(int x,int fa) {
    dfn[x]=low[x]=++vs; sta.push_back(x);
    for(int i=fir[x];i;i=nxt[i]) {
        if(broken[i]) continue;
        int y=ver[i];
        if(!dfn[y]) {
            dfs(y,x);
            low[x]=min(low[x],low[y]);
            if(dfn[x]<=low[x]) {
                int cnt=0, pl=0, pr=0, z=0;
                do {
                    z=sta.back();
                    if(!pl) pl=z;
                    pr=z;
                    ans.push_back(z+cnt*n);
                    sta.pop_back();
                    cnt^=1;
                }while(z!=y);
                if(!pl) continue;
                if(cnt==1) ans.push_back(pl+n), ans.push_back(pr+n);
                else ans.push_back(pl+n), ans.push_back(pr);
            }
        }else if(y!=fa) low[x]=min(low[x],dfn[y]);
    }
    return ;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++) {
        int u,v; cin>>u>>v;
        add(u,v);
        deg[u]++, deg[v]++;
    }
    for(int i=1;i<=n;i++) if(deg[i]&1) dfs(i);
    ans.push_back(0);
    for(int i=1;i<=n;i++) {
        if(!dfn[i]) {
            sta.clear();
            dfs(i,0), ans.push_back(i);
        }
    }
    cout<<0<<' '<<ans.size()<<'\n';
    for(auto x:ans) {
        if(x>0) cout<<1<<' '<<x<<'\n';
        else cout<<2<<'\n';
    }
    return 0;
}

詳細信息

Test #1:

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

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 0ms
memory: 35580kb

input:

7 7
1 2
1 3
2 3
2 4
2 5
3 6
3 7

output:

0 11
1 4
1 2
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: 115ms
memory: 46876kb

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 521163
1 3
1 274816
1 273658
1 231418
1 293414
1 210743
1 117739
1 217554
1 234392
1 48428
1 210477
1 127525
1 217572
1 248509
1 8
1 57067
1 9
1 10
1 18682
1 297029
1 148043
1 194189
1 287574
1 143622
1 247826
1 170188
1 66660
1 206230
1 26612
1 7163
1 298776
1 92709
1 69100
1 297777
1 267639
1 23...

result:

wrong answer The deg of 457129 is not odd.