QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327943#1844. Cactusc20230201WA 4ms10724kbC++142.0kb2024-02-15 15:40:012024-02-15 15:40:02

Judging History

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

  • [2024-02-15 15:40:02]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10724kb
  • [2024-02-15 15:40:01]
  • 提交

answer

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

const int maxn=3e5+5;

int vs, tot, cnt, 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;
                while(sta.back()!=x) {
                    int z=sta.back();
                    if(!pl) pl=z;
                    pr=z;
                    ans.push_back(z+cnt*n);
                    sta.pop_back();
                    cnt^=1;
                }
                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]) 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: 4ms
memory: 10724kb

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: -100
Wrong Answer
time: 0ms
memory: 10672kb

input:

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

output:

0 17
1 4
1 2
1 5
1 2
1 4
1 3
1 6
1 1
1 2
2
1 1
1 2
1 3
1 4
1 5
1 6
1 7

result:

wrong answer The deg of 5 is not odd.