QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50752 | #1256. Delete Two Vertices Again | tricyzhkx | WA | 7ms | 32184kb | C++14 | 3.2kb | 2022-09-29 09:41:15 | 2022-09-29 09:41:16 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
int n,lc[6000010],rc[6000010],sum[6000010],rt[300010],bad[300010],L[300010],R[300010],dep[300010],low[300010],minn[20][300010],fa[20][300010],tot;
char ans[300010];
struct Edge{int u,v;}e[300010];
vector<int> G[300010],T[300010],up[300010],E[300010];
bool vis[300010],ban[300010];
struct BIT
{
int s[300010];
void update(int x,int y){for(int i=x;i<=n;i+=i&(-i)) s[i]+=y;}
void update(int l,int r,int x){update(l,x);update(r+1,-x);}
int query(int x)
{
int ans=0;
for(int i=x;i;i-=i&(-i)) ans+=s[i];
return ans;
}
}B;
void update(int &rt,int l,int r,int x)
{
if(!rt) rt=++tot;
if(l==r) return sum[rt]=1,void();
int mid=(l+r)/2;
if(x<=mid) update(lc[rt],l,mid,x);
else update(rc[rt],mid+1,r,x);
sum[rt]=sum[lc[rt]]+sum[rc[rt]];
}
int query(int rt,int l,int r,int x)
{
if(l>x || !sum[rt]) return -1;
if(l==r) return l;
int mid=(l+r)/2,t;
if(r<=x)
{
if(sum[rc[rt]]) return query(rc[rt],mid+1,r,x);
else return query(lc[rt],l,mid,x);
}
if((t=query(rc[rt],mid+1,r,x))>0) return t;
else return query(lc[rt],l,mid,x);
}
int merge(int x,int y,int l,int r)
{
if(!x || !y) return x+y;
if(l==r) return sum[x]|=sum[y],x;
int mid=(l+r)/2;
lc[x]=merge(lc[x],lc[y],l,mid);rc[x]=merge(rc[x],rc[y],mid+1,r);
sum[x]=sum[lc[x]]+sum[rc[x]];
return x;
}
void dfs1(int u)
{
low[u]=dep[u];vis[u]=1;
for(int v:G[u])
{
if(v==fa[0][u]) continue;
if(!vis[v])
{
dep[v]=dep[u]+1;fa[0][v]=u;
cout<<u<<"-->"<<v<<endl;
T[u].push_back(v);dfs1(v);
low[u]=min(low[u],low[v]);
}
else if(dep[v]<dep[u]) up[u].push_back(dep[v]),low[u]=min(low[u],dep[v]);
}
}
void dfs2(int u)
{
for(int v:T[u]) dfs2(v);
bool ok=1;
for(int v:T[u])
{
L[v]=low[v];R[v]=query(rt[v],1,n,dep[u]-1);
rt[u]=merge(rt[u],rt[v],1,n);
if(L[v]>R[v]) ok=0;
}
for(int i:up[u]) update(rt[u],1,n,i);
if(!ok)
{
for(int i:E[u]) ans[i]='0';
return;
}
for(int v:T[u])
if(L[v]==R[v]) ban[L[v]]=1;
else B.update(L[v]+1,R[v]-1,1);
for(int i:E[u])
{
int v=e[i].v,w=u,mn=1e9;
if(fa[0][u]==v && v==1 && T[u].empty())
{
ans[i]=((int)T[v].size()<=2?'1':'0');
continue;
}
if(fa[0][u]==v) mn=0;
else
{
w=fa[0][u];
for(int j=18;j>=0;j--)
if(dep[fa[j][w]]>dep[v])
mn=min(mn,minn[j][w]),w=fa[j][w];
mn=min(mn,minn[0][w]);
}
if(bad[v]-(low[w]>=dep[w]-1)>0 || ban[dep[v]]){ans[i]='0';continue;}
if(mn>=dep[v] && !B.query(dep[v])) ans[i]='0';
else ans[i]='1';
}
for(int v:T[u])
if(L[v]==R[v]) ban[L[v]]=0;
else B.update(L[v]+1,R[v]-1,-1);
}
int main()
{
int m;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
scanf("%d%d",&e[i].u,&e[i].v);
G[e[i].u].push_back(e[i].v);G[e[i].v].push_back(e[i].u);
}
dep[1]=1;dfs1(1);
for(int i=1;i<=n;i++)
{
minn[0][i]=1e9;
for(int j:up[i]) minn[0][i]=min(minn[0][i],j);
}
for(int i=1;i<=18;i++)
for(int j=1;j<=n;j++)
fa[i][j]=fa[i-1][fa[i-1][j]],
minn[i][j]=min(minn[i-1][j],minn[i-1][fa[i-1][j]]);
for(int i=2;i<=n;i++)
if(low[i]>=dep[i]-1) bad[fa[0][i]]++;
for(int i=1;i<=m;i++)
{
if(dep[e[i].u]<dep[e[i].v]) swap(e[i].u,e[i].v);
E[e[i].u].push_back(i);
}
dfs2(1);
printf("%s\n",ans+1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 32184kb
input:
4 4 1 2 2 3 3 1 4 1
output:
1-->2 2-->3 1-->4 0101
result:
wrong answer Line "1-->2" doesn't correspond to pattern "[0-1]{1,5000000}"