QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#327956#1844. Cactusc20230201RE 0ms15200kbC++142.0kb2024-02-15 15:43:512024-02-15 15:43:51

Judging History

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

  • [2024-02-15 15:43:51]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:15200kb
  • [2024-02-15 15:43:51]
  • 提交

answer

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

const int maxn=3e5+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;
                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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 14544kb

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