QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327672#1844. CactuszyxawaWA 220ms52012kbC++141.8kb2024-02-15 11:52:082024-02-15 11:52:09

Judging History

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

  • [2024-02-15 11:52:09]
  • 评测
  • 测评结果:WA
  • 用时:220ms
  • 内存:52012kb
  • [2024-02-15 11:52:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define add(x) ans.push_back(x)
int n,m,u,v,tot,cnt,top,stk[300001],deg[300001],vis[300001],dfn[300001],low[300001],s[300001];
vector <int> ans,G[300001],W[300001],E[600001];
void del(int x){
    vis[x]=1,add(x);
    for(auto y:W[x]) deg[y]^=1;
    for(auto y:W[x]) if(deg[y]&&!vis[y]) del(y);
}
void tarjan(int u,int x){
    dfn[u]=low[u]=++tot,stk[++top]=u;
    for(auto v:G[u]){
        if(!dfn[v]){
            tarjan(v,u),low[u]=min(low[u],low[v]);
            if(dfn[u]<=low[v]){
                E[++cnt].push_back(u),E[u].push_back(cnt);
                while(stk[top+1]!=v) E[stk[top]].push_back(cnt),E[cnt].push_back(stk[top--]);
            }
        }
        else if(v!=x) low[u]=min(low[u],dfn[v]);
    }
}
void dfs(int x,int lst){
    vis[x]=1;
    for(auto y:E[x]) if(!vis[y]) dfs(y,x);
    if(x<=n&&!lst) add(x);
    if(x<=n) return;
    int len=0,str=0;
    for(int i=0;i<E[x].size();i++) if(E[x][i]==lst) str=i;
    for(int i=str;i<E[x].size();i++) s[++len]=E[x][i];
    for(int i=0;i<str;i++) s[++len]=E[x][i];
    for(int i=2;i<=len;i++) add(s[i]+(i&1)*n);
    if(E[x].size()&1) add(s[2]+n),add(s[len]);
    else add(s[2]+n),add(s[len]+n);
}
int main(){
	scanf("%d%d",&n,&m),cnt=n;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        W[u].push_back(v),deg[u]^=1;
        W[v].push_back(u),deg[v]^=1;
    }
    for(int i=1;i<=n;i++) if(deg[i]&&!vis[i]) del(i);
    for(int i=1;i<=n;i++) for(auto j:W[i]) if(!vis[i]&&!vis[j]) G[i].push_back(j);
    memset(vis,0,sizeof(vis)),add(0);
    for(int i=1;i<=n;i++) if(!dfn[i]) tarjan(i,0);
    for(int i=1;i<=n;i++) if(!vis[i]) dfs(i,0);
    printf("0 %ld\n",ans.size());
    for(auto i:ans){
        if(i!=0) printf("1 %d\n",i);
        else printf("2\n");
    }
	return 0;
}

詳細信息

Test #1:

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

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

score: 0
Accepted
time: 8ms
memory: 35016kb

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: 220ms
memory: 52012kb

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 513579
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 1864 is not odd.