QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328006#1844. Cactusc20230201WA 181ms68368kbC++142.1kb2024-02-15 16:05:312024-02-15 16:05:31

Judging History

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

  • [2024-02-15 16:05:31]
  • 评测
  • 测评结果:WA
  • 用时:181ms
  • 内存:68368kb
  • [2024-02-15 16:05:31]
  • 提交

answer

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

const int maxn=1e6+5;

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

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

void dfs(int x) {
    deg[x]=0; vis[x]=1;
    ans.push_back(x);
    for(int y:g[x]) {
        if(vis[y]) continue;
        deg[y]--;
    }
    for(int y:g[x]) 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;
        g[u].push_back(v);
        g[v].push_back(u);
        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++) {
        for(int j:g[i]) {
            if(vis[i]||vis[j]) continue;
            add(i,j);
        }
    }
    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: 8ms
memory: 51228kb

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: 3ms
memory: 52464kb

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: 181ms
memory: 68368kb

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 521049
1 3
1 274816
1 273658
1 217572
1 248509
1 231418
1 73094
1 117739
1 11855
1 48428
1 55953
1 121689
1 234392
1 181317
1 238712
1 77369
1 105062
1 6838
1 130659
1 8
1 44304
1 9
1 10
1 18682
1 63155
1 148043
1 194189
1 26612
1 1155
1 31020
1 108936
1 71065
1 77412
1 124995
1 126920
1 53663
1 4...

result:

wrong answer The deg of 111834 is not odd.