QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#329618 | #1844. Cactus | CharlieVinnie | WA | 428ms | 61416kb | C++17 | 2.1kb | 2024-02-16 23:02:42 | 2024-02-16 23:02:43 |
Judging History
answer
#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#define debuga(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
constexpr int N=3e5+5;
int n,m,dfn[N],low[N],dfscnt,st[N],tp; set<int> to[N]; vector<int> Ans1,Ans2;
void solve(vector<int> lis){
int k=lis.size();
if(~k&1){
For(i,0,k-1) if(~i&1) Ans2.push_back(lis[i]); else Ans2.push_back(lis[i]+n);
Ans2.push_back(lis[k-1]); Ans2.push_back(lis[0]+n);
}
else{
For(i,0,k-1) if(i&1) Ans2.push_back(lis[i]); else Ans2.push_back(lis[i]+n);
Ans2.push_back(lis[0]); Ans2.push_back(lis[k-1]);
}
}
void dfs(int u,int pa){
dfn[u]=low[u]=++dfscnt; st[++tp]=u;
for(int v:to[u]) if(v!=pa) {
if(!dfn[v]){
dfs(v,u),low[u]=min(low[u],low[v]);
if(low[v]==dfn[u]){
vector<int> lis;
while(st[tp]!=u) lis.push_back(st[tp--]);
solve(lis);
}
}
else low[u]=min(low[u],dfn[v]);
}
}
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
cin>>n>>m; For(i,1,m) { int x,y; cin>>x>>y; to[x].insert(y); to[y].insert(x); }
set<int> S; For(i,1,n) if(to[i].size()&1) S.insert(i);
while(S.size()){
int u=*S.begin(); Ans1.push_back(u); S.erase(S.begin());
for(int v:to[u]){
to[v].erase(u); if(to[v].size()&1) S.insert(v); else S.erase(v);
}
to[u].clear();
}
For(i,1,n) if(!dfn[i]) dfs(i,0),Ans2.push_back(i);
cout<<0<<' '<<Ans1.size()+Ans2.size()+1<<'\n';
for(int x:Ans1) cout<<1<<' '<<x<<'\n';
cout<<"2\n";
for(int x:Ans2) cout<<1<<' '<<x<<'\n';
return 0;
}
// CONTINUE, NON-STOPPING, FOR CHARLIEY
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// Started Coding On: February 16 Fri, 22 : 35 : 37
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18340kb
input:
3 3 1 2 1 3 2 3
output:
0 6 2 1 3 1 5 1 2 1 6 1 1
result:
ok You are right!
Test #2:
score: 0
Accepted
time: 0ms
memory: 17988kb
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: 428ms
memory: 61416kb
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 522748 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 37448 is not odd.