QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328268#1844. CactuslefyWA 4ms36032kbC++142.7kb2024-02-15 18:46:022024-02-15 18:46:02

Judging History

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

  • [2024-02-15 18:46:02]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:36032kb
  • [2024-02-15 18:46:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=3e5+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;
        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,st[N],top;
vector<int>b[N<<1];
vector<int>hav[N];
void Tarjan(int x){
    st[++top]=x;
    vis[x]=2,dfn[x]=low[x]=++idd;
    for(int v:e[x])if(vis[v]!=1){
        if(!dfn[v]){
            Tarjan(v);
            low[x]=min(low[x],low[v]);
            if(low[v]>=dfn[x]){
                dcc++;int y=0;
                b[dcc+n].push_back(x);b[x].push_back(dcc+n);
                du[x]++,du[dcc+n]++;
                hav[dcc].push_back(x);
                while(st[top]^x){
                    y=st[top--];
                    hav[dcc].push_back(y);
                    b[y].push_back(dcc+n),b[dcc+n].push_back(y);
                    du[y]++,du[dcc+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]);
    memset(du,0,sizeof(du));
    for(int i=1;i<=n;i++)if(!vis[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;
        int sz=hav[x-n].size();x-=n;
        tmp=hav[x][0];
        for(int i=1;i<sz;i+=2)if(sz-i==3){
            ans.push_back(hav[x][sz-1]);
            ans.push_back(hav[x][sz-2]+n);
            ans.push_back(hav[x][sz-3]+n);
            ans.push_back(hav[x][sz-3]);
            ans.push_back(hav[x][sz-2]);
            ans.push_back(hav[x][sz-1]+n);
        }else{
            ans.push_back(hav[x][i]);
            ans.push_back(hav[x][i+1]+n);
            ans.push_back(hav[x][i+1]);
            ans.push_back(hav[x][i]+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());
    int flag=0;
    for(int x:ans){
        if(x==-1)printf("2\n"),flag=1;
        else {
            if(flag)cout<<"*";
            printf("1 %d\n",x);
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 36032kb

input:

3 3
1 2
1 3
2 3

output:

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

result:

wrong output format Expected integer, but "*1" found