QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#328066 | #1844. Cactus | 11d10xy | WA | 28ms | 96076kb | C++14 | 1.0kb | 2024-02-15 16:44:53 | 2024-02-15 16:44:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,tot,st[300010],vis[300010],tp;
set<int>G[300010];
basic_string<int>ans,cir[300010];
void dfs(int u,int fa){
st[++tp]=u,vis[u]=1;
for(int v:G[u])if(v!=fa)if(!vis[v]){
dfs(v,u);
if(cir[u].empty())continue;
cir[u].pop_back();
int s=cir[u].size();
for(int i=0;i<s;i++)ans+=cir[u][i]+(i&1)*n;
for(int i=0;i<s;i++)ans+=cir[u][i]+(~i&1)*n;
}else{cir[v]={};for(int i=tp;st[i+1]!=v;cir[v]+=st[i--]);G[v].erase(u);}
tp--;
}
int main(){
cin>>n>>m;
for(int u,v;m--;)scanf("%d%d",&u,&v),G[u].insert(v),G[v].insert(u);
set<int>s;
for(int i=1;i<=n;i++)if(G[i].size()&1)s.insert(i);
for(int u;!s.empty();){
u=*begin(s),s.erase(u),ans+=u;
for(int v:G[u]){
if(G[v].size()&1)s.erase(v);
else s.insert(v);
G[v].erase(u);
}
}
ans+=0;
for(int i=1;i<=n;i++)if(!vis[i])dfs(i,0),ans+=i;
printf("0 %d\n",(int)ans.size());
for(int x:ans)if(x)printf("1 %d\n",x);else puts("2");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 29424kb
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
Wrong Answer
time: 28ms
memory: 96076kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 10 1 4 1 2 1 1 1 6 1 3 2 1 1 1 2 1 4 1 6
result:
wrong answer The number of remaining edges is not equal to m'.