QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#328478#1844. CactuslefyWA 172ms68500kbC++143.7kb2024-02-15 20:21:152024-02-15 20:21:17

Judging History

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

  • [2024-02-15 20:21:17]
  • 评测
  • 测评结果:WA
  • 用时:172ms
  • 内存:68500kb
  • [2024-02-15 20:21:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=6e5+10;
vector<int>e[N];
void add(int u,int v){
    e[u].push_back(v);
}
vector<int>ans;
int du[N<<1],n,m,vis[N];
void solve1(){
    queue<int>q;
    for(int i=1;i<=n;i++)if(du[i]&1)q.push(i);
    while(!q.empty()){
        int x=q.front();q.pop();
        if(vis[x]||du[x]%2==0)continue;
        vis[x]=1;du[x]=0;
        for(int v:e[x])if(!vis[v]){
            du[v]--;
            if(du[v]&1)q.push(v);
        }
        ans.push_back(x);
    }
}
int dcc,be[N],dfn[N],low[N],idd,top;
pair<int,int>st[N];
vector<int>b[N<<1];
void Tarjan(int x){
    dfn[x]=low[x]=++idd;
    // if(x==968||x==14118||x==7310)cout<<x<<"\n";
    for(int v:e[x])if(!vis[v]){
        if(!dfn[v]){
            st[++top]={x,v};
            Tarjan(v);
            low[x]=min(low[x],low[v]);
            
            if(low[v]>=dfn[x]){
                // cout<<x<<" "<<v<<"*\n";
                dcc++;int y=0;
                b[dcc+n].push_back(x);b[x].push_back(dcc+n);
                du[x]++,du[dcc+n]++;
                while(1){
                    y=st[top--].second;
                    // cout<<y<<" ";
                    // if(x==968)cout<<y<<"*\n";
                    b[y].push_back(dcc+n),b[dcc+n].push_back(y);
                    du[y]++,du[dcc+n]++;
                    if(st[top+1]==make_pair(x,v))break;
                }
                // if(x==968)cout<<dcc<<"\n";
                // cout<<x<<"\n";
            }
        }else low[x]=min(low[x],dfn[v]);
    }
}

void solve2(){
    ans.push_back(-1);int sz=ans.size();
    for(int i=0;i<sz-1;i++)ans.push_back(ans[i]);
    if(n>1000){
        // cout<<du[56967]<<" "<<du[14118]<<"\n";
        // for(int v:e[968])if(!vis[v])cout<<v<<"\n";
    }
    memset(du,0,sizeof(du));
    for(int i=1;i<=n;i++)if(!vis[i]&&!dfn[i])Tarjan(i);
    queue<int>q;for(int i=1;i<=n+dcc;i++)if(du[i]==1)q.push(i);
    int tmp=0;
    while(!q.empty()){
        int x=q.front();q.pop();
        for(int v:b[x]){
            du[v]--;
            if(du[v]==1)q.push(v);
        }
        if(x<=n)continue;
        sz=b[x].size();
        // if(b[x][1]==56967)cout<<b[x][0]<<" "<<du[56967]<<"\n";
        tmp=b[x][0];
        for(int i=1;i<sz;i+=2)if(sz-i==3){
            if(i!=1)
            ans.push_back(b[x][sz-1]),
            ans.push_back(b[x][sz-2]+n),
            ans.push_back(b[x][sz-3]+n),
            ans.push_back(b[x][sz-3]),
            ans.push_back(b[x][sz-1]+n);
            else ans.push_back(b[x][sz-1]),
            ans.push_back(b[x][sz-2]+n),
            ans.push_back(b[x][sz-1]+n),
            ans.push_back(b[x][sz-3]),
            ans.push_back(b[x][sz-3]+n);
            
            break;
        }else{
            if(b[x][i]==56967||b[x][i+1]==56967)cout<<b[x][i+1]<<" "<<b[x][0]<<"\n";
            // if(i+1>=sz)cout<<hav[x][0]<<" "<<hav[x][1]<<" "<<sz<<" "<<x<< "\n";
            if(i==1)ans.push_back(b[x][i]),ans.push_back(b[x][i+1]+n),ans.push_back(b[x][i+1]),ans.push_back(b[x][i]+n);
            else ans.push_back(b[x][i+1]),ans.push_back(b[x][i]),ans.push_back(b[x][i]+n),ans.push_back(b[x][i+1]+n);
        }
    }
    ans.push_back(tmp);
}
int main() {
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        add(x,y),add(y,x);
        du[x]++,du[y]++;
    }
    solve1();
    if(ans.size()!=n)solve2();
    printf("0 %d\n",(int)ans.size());
    for(int x:ans){
        // if(n<=1000){
            if(x==-1)printf("2\n");
        else printf("1 %d\n",x);
        // }
        // else if(x>2*n)cout<<x<<"**\n";
        
        
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 52468kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

ok You are right!

Test #2:

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

input:

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

output:

0 14
1 4
1 5
1 6
1 7
2
1 4
1 5
1 6
1 7
1 3
1 9
1 2
1 10
1 1

result:

ok You are right!

Test #3:

score: -100
Wrong Answer
time: 172ms
memory: 68500kb

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:

56451 147636
0 454464
1 3
1 8
1 9
1 10
1 11
1 16
1 20
1 21
1 25
1 28
1 29
1 30
1 32
1 33
1 34
1 41
1 42
1 43
1 44
1 47
1 48
1 53
1 54
1 55
1 57
1 59
1 62
1 65
1 73
1 75
1 77
1 80
1 81
1 87
1 88
1 94
1 95
1 101
1 102
1 103
1 106
1 112
1 123
1 128
1 129
1 133
1 136
1 137
1 138
1 140
1 141
1 143
1 145
...

result:

wrong answer Integer parameter [name=m'] equals to 56451, violates the range [0, 0]