QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50757 | #1256. Delete Two Vertices Again | tricyzhkx | WA | 5ms | 33616kb | C++14 | 3.5kb | 2022-09-29 10:10:27 | 2022-09-29 10:10:28 |
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],top[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;
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]);
}
top[u]=dep[u];
for(int i:up[u]) top[u]=min(top[u],i);
int mn1=0,mn2=0;
for(int v:T[u])
if(!mn1 || low[v]<low[mn1]) mn2=mn1,mn1=v;
else if(!mn2 || low[v]<low[mn2]) mn2=v;
for(int v:T[u])
if(mn1==v) minn[0][v]=low[mn2];
else minn[0][v]=low[mn1];
}
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);
for(int v:T[u])
if(L[v]==R[v]) ban[L[v]]=1;
else if(L[v]<R[v]) 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)
{
if((int)T[v].size()>=2 && !T[u].empty()) ans[i]='0';
else if(T[u].empty()) ans[i]=((int)T[v].size()<=2?'1':'0');
else ans[i]=((int)T[u].size()<=1?'1':'0');
continue;
}
if(!ok){ans[i]='0';continue;}
if(fa[0][u]==v) mn=0;
else
for(int j=18;j>=0;j--)
if(dep[fa[j][w]]>dep[v])
mn=min(mn,minn[j][w]),w=fa[j][w];
if(bad[v]-(low[w]>=dep[w]-1)>0 || ban[dep[v]]){ans[i]='0';continue;}
if(v>1 && 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 if(L[v]<R[v]) B.update(L[v]+1,R[v]-1,-1);
}
int main()
{
low[0]=1e9;
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<=18;i++)
for(int j=1;j<=n;j++)
fa[i][j]=fa[i-1][fa[i-1][j]],
minn[i][j]=min(top[fa[i-1][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;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 33020kb
input:
4 4 1 2 2 3 3 1 4 1
output:
0101
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #2:
score: 0
Accepted
time: 5ms
memory: 32416kb
input:
3 3 1 2 2 3 3 1
output:
111
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #3:
score: 0
Accepted
time: 0ms
memory: 32200kb
input:
3 2 1 2 2 3
output:
11
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #4:
score: 0
Accepted
time: 3ms
memory: 33616kb
input:
6 7 1 2 1 3 1 6 2 4 3 4 3 5 4 6
output:
1011011
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 32816kb
input:
10 39 1 2 1 3 1 5 1 6 1 7 1 8 1 9 1 10 2 3 2 4 2 5 2 6 2 9 2 10 3 5 3 6 3 7 3 8 3 10 4 5 4 6 4 7 4 9 4 10 5 6 5 7 5 8 5 9 5 10 6 7 6 8 6 9 6 10 7 8 7 9 7 10 8 9 8 10 9 10
output:
111111111111111111111111111111111111101
result:
wrong answer Deleting vertices 8 and 10 makes graph connected, but participant claims otherwise.