QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328298 | #1844. Cactus | 11d10xy | WA | 278ms | 68408kb | C++14 | 1.1kb | 2024-02-15 18:58:22 | 2024-02-15 18:58:23 |
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;
ans+={cir[u][0]+n,cir[u].back()+int(cir[u].size()&1)*n};cir[v]={};
}else{for(int i=tp;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);
}G[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 28668kb
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: 0
Accepted
time: 3ms
memory: 28944kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 13 1 4 1 2 1 1 1 6 1 3 2 1 1 1 2 1 3 1 4 1 5 1 6 1 7
result:
ok You are right!
Test #3:
score: -100
Wrong Answer
time: 278ms
memory: 68408kb
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:
0 529511 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 1 146 1 150 1...
result:
wrong answer The deg of 269879 is not odd.