QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#328053 | #1844. Cactus | fansizhe | WA | 195ms | 65956kb | C++23 | 2.0kb | 2024-02-15 16:35:19 | 2024-02-15 16:35:20 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
set<int> edge[300005];
vector<int> ans;
vector<int> e1[600005];
int tot;
int dfn[300005],low[300005],cnt;
stack<int> st;
int vis[300005];
void dfs1(int x){
ans.push_back(x);
set<int> S;swap(S,edge[x]);
for(int y:S)edge[y].erase(x);
for(int y:S)if(edge[y].size()&1)dfs1(y);
}
void addedge(int x,int y){
e1[x].push_back(y);
e1[y].push_back(x);
}
void Tarjan(int x){
dfn[x]=low[x]=++cnt;
st.push(x);
for(int y:edge[x])
if(!dfn[y]){
Tarjan(y);
low[x]=min(low[x],low[y]);
if(low[y]>=dfn[x]){
tot++;
int z;
do{
z=st.top();st.pop();
addedge(z,tot);
}while(z!=y);
addedge(x,tot);
}
}else low[x]=min(low[x],dfn[y]);
}
void dfs2(int x,int f){
for(int y:e1[x])if(y!=f)dfs2(y,x);
if(x>n){
int p=0;
for(int i=0;i<e1[x].size();i++)if(e1[x][i]==f){p=i;break;}
for(int i=0;i+1<e1[x].size();i++)assert(edge[e1[x][i]].find(e1[x][i+1])!=edge[e1[x][i]].end());
assert(edge[e1[x][0]].find(e1[x].back())!=edge[e1[x][0]].end());
int flag=1;
for(int i=p+1;i<e1[x].size();i++,flag^=1)
if(flag)ans.push_back(e1[x][i]);
else ans.push_back(e1[x][i]+n);
for(int i=0;i<p;i++,flag^=1)
if(flag)ans.push_back(e1[x][i]);
else ans.push_back(e1[x][i]+n);
flag=0;
for(int i=p+1;i<e1[x].size();i++,flag^=1)
if(flag)ans.push_back(e1[x][i]);
else ans.push_back(e1[x][i]+n);
for(int i=0;i<p;i++,flag^=1)
if(flag)ans.push_back(e1[x][i]);
else ans.push_back(e1[x][i]+n);
}else vis[x]=1;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
edge[x].insert(y);
edge[y].insert(x);
}
for(int i=1;i<=n;i++)if(edge[i].size()&1)dfs1(i);
ans.push_back(0);
tot=n;
for(int i=1;i<=n;i++)if(!dfn[i])Tarjan(i);
for(int i=1;i<=n;i++)if(!vis[i])dfs2(i,0),ans.push_back(i);
printf("0 %d\n",(int)ans.size());
for(int x:ans)if(x>0)printf("1 %d\n",x);else puts("2");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 21244kb
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: 0ms
memory: 22368kb
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: 195ms
memory: 65956kb
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 522894 1 3 1 274816 1 273658 1 217572 1 248509 1 231418 1 73094 1 117739 1 11855 1 48428 1 55953 1 121689 1 234392 1 181317 1 238712 1 77369 1 105062 1 6838 1 130659 1 8 1 44304 1 9 1 10 1 18682 1 63155 1 148043 1 194189 1 26612 1 1155 1 31020 1 108936 1 71065 1 77412 1 124995 1 126920 1 53663 1 4...
result:
wrong answer The deg of 190282 is not odd.