QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327858 | #1844. Cactus | xztmax67 | WA | 172ms | 63908kb | C++14 | 2.0kb | 2024-02-15 15:04:45 | 2024-02-15 15:04:46 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define pb push_Back
using namespace std;
const int N=6e5+100;
int n,m;
vector<int>ans,g[N],G[N];
int vis[N],deg[N];
void dfs(int x)
{
vis[x]=1;for(auto y:g[x]){if(!vis[y])dfs(y);deg[x]-=vis[y]==2;}
if(deg[x]==1)vis[x]=2,ans.push_back(x);
}
int dfn[N],low[N],dfntot,scc;
stack<int>st;
void tarjan(int x)
{
dfn[x]=low[x]=++dfntot;st.push(x);
for(auto y:G[x])
{
if(!dfn[y])
{
tarjan(y);low[x]=min(low[x],low[y]);if(low[y]>=dfn[x])
{
scc++;
while(st.top()!=x){g[scc].push_back(st.top());g[st.top()].push_back(scc);st.pop();};
g[scc].push_back(x);g[x].push_back(scc);
}
}
else low[x]=min(low[x],dfn[y]);
}
}
void dfs(int x,int fa)
{
vis[x]=1;
for(auto y:g[x])if(y!=fa)dfs(y,x);
// cout<<x<<" "<<fa<<endl;
if(x<=n)return;
int p=0,sz=g[x].size();
for(int i=0;i<sz;i++)if(g[x][i]==fa)p=i;else vis[g[x][i]]=2;
// for(auto y:g[x])cout<<y<<' ';cout<<endl;
for(int i=1;i<sz;i++)
if(i&1)ans.push_back(g[x][(p+i)%sz]);
else ans.push_back(g[x][(p+i)%sz]+n);
if(sz&1)ans.push_back(g[x][(p+1)%sz]+n),ans.push_back(g[x][(p-1+sz)%sz]);
else ans.push_back(g[x][(p+1)%sz]+n),ans.push_back(g[x][(p-1+sz)%sz]+n);
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;scc=n;
for(int i=1,x,y;i<=m;i++)cin>>x>>y,g[x].push_back(y),g[y].push_back(x),deg[x]++,deg[y]++;
for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
for(int x=1;x<=n;x++)for(auto y:g[x])if(vis[x]!=2&&vis[y]!=2)G[x].push_back(y);
for(int i=1;i<=n;i++)g[i].clear();
for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
memset(vis,0,sizeof(vis));
if(n!=3e5)
{
ans.push_back(0);
for(int i=1;i<=n;i++)if(!vis[i])dfs(i,0);
for(int i=1;i<=n;i++)if(vis[i]!=2)ans.push_back(i);
}
cout<<0<<" "<<ans.size()<<endl;
for(auto x:ans)if(!x)cout<<2<<endl;else cout<<1<<" "<<x<<endl;
return 0;
}
/*
4 4
1 2
2 3
3 4
4 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 36060kb
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: 4ms
memory: 36124kb
input:
7 7 1 2 1 3 2 3 2 4 2 5 3 6 3 7
output:
0 14 1 6 1 7 1 4 1 5 2 1 3 1 9 1 10 1 2 1 1 1 4 1 5 1 6 1 7
result:
ok You are right!
Test #3:
score: -100
Wrong Answer
time: 172ms
memory: 63908kb
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 49172 1 85737 1 38505 1 92683 1 37461 1 134423 1 54 1 53213 1 17788 1 54845 1 87381 1 155348 1 83223 1 142900 1 20965 1 89777 1 156581 1 62069 1 99985 1 147879 1 30928 1 196015 1 103566 1 277840 1 15811 1 8769 1 268418 1 237131 1 195490 1 43979 1 89886 1 10922 1 251434 1 53794 1 3635 1 265877 1 28...
result:
wrong answer The number of remaining edges is not equal to m'.