QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327676#1844. CactuszyxawaML 11ms36928kbC++141.8kb2024-02-15 11:53:202024-02-15 11:53:21

Judging History

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

  • [2024-02-15 11:53:21]
  • 评测
  • 测评结果:ML
  • 用时:11ms
  • 内存:36928kb
  • [2024-02-15 11:53:20]
  • 提交

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,deg[x]=1,add(x);
    for(auto y:W[x]) if(!vis[y]) deg[y]^=1;
    for(auto y:W[x]) if(deg[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]) 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: 11ms
memory: 36928kb

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: -100
Memory Limit Exceeded

input:

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

output:


result: