QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327661 | #1844. Cactus | zyxawa | WA | 4ms | 33516kb | C++14 | 1.8kb | 2024-02-15 11:47:43 | 2024-02-15 11:47:44 |
Judging History
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(E[x].empty()) 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 33516kb
input:
3 3 1 2 1 3 2 3
output:
0 5 2 1 3 1 5 1 6 1 2
result:
wrong answer The number of remaining edges is not equal to m'.