QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#50758 | #1256. Delete Two Vertices Again | tricyzhkx | WA | 389ms | 112220kb | C++14 | 3.5kb | 2022-09-29 10:14:38 | 2022-09-29 10:14:39 |
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];
mn=min(mn,min(top[w],minn[0][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: 32200kb
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: 3ms
memory: 32052kb
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: 5ms
memory: 32140kb
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: 1ms
memory: 31992kb
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: 0
Accepted
time: 5ms
memory: 32164kb
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:
111111111111111111111111111111111111111
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #6:
score: 0
Accepted
time: 4ms
memory: 31992kb
input:
10 12 1 6 1 7 2 5 2 8 3 4 3 6 4 6 4 10 5 9 5 10 6 9 7 10
output:
110111010011
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #7:
score: 0
Accepted
time: 389ms
memory: 112164kb
input:
300000 300000 1 125583 1 226455 2 42202 2 265465 2 292498 3 199795 4 241628 5 96520 6 100749 6 213843 7 186924 8 239025 8 286308 9 103103 10 161146 11 81159 11 151301 12 6769 12 175614 12 262561 13 165510 14 107584 14 155920 14 166283 14 186225 15 24511 15 105534 15 263647 16 16253 16 141758 16 2560...
output:
000001010101001100001000000000000000010000000000000000000000000001000010100000001000100000000000000000000000000000000001001100000100000000000000000001000000000000000000000100001000000010000010110100100000001010010101000100000000000000010000000000000000000010000000000000110000010000101000001000000001...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #8:
score: 0
Accepted
time: 360ms
memory: 112184kb
input:
300000 300000 1 162811 2 138525 2 205299 2 288706 3 60572 3 74088 3 127663 4 246045 5 45829 5 252773 6 15469 6 257288 6 288184 7 82681 7 173462 8 124407 9 2612 9 48156 9 118342 10 43567 10 294037 11 63181 11 168420 11 250865 12 151307 12 158808 13 64625 13 266232 14 276021 15 142611 16 62738 16 1765...
output:
000000000000001000000000101001000010000010000010000000100010000000000000000000000010100000000000101001000000000000000000000000000000000000000100000001110000000000000000000000010010100000000000000001000000000000000000000101000000101010001000101000000000000000000001100000001000001000000000100000000000...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #9:
score: 0
Accepted
time: 379ms
memory: 112220kb
input:
300000 300000 1 34885 2 96948 2 168723 2 187175 3 5835 4 156187 4 165385 4 294023 5 86353 5 185975 5 252890 6 73705 7 59212 7 164589 8 140432 9 96944 9 100558 10 33019 11 25103 11 244580 11 297854 12 165955 12 213096 13 68011 13 69872 13 201627 14 174660 15 103457 15 276269 16 55924 16 186094 17 256...
output:
000000000001000000000000001000011000000000000000000110000000010001000100000100000010000000000000000010010000101000000000010000000000000000000000011000010000100001100000010000000000010110101100110000000000000000001000010111100100000000000000000000001000000000110000000000000000000000000000000000000000...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #10:
score: 0
Accepted
time: 359ms
memory: 112116kb
input:
300000 300000 1 177874 2 8218 3 198060 4 214435 5 188360 5 207173 5 277097 6 231421 7 132370 7 235234 8 207170 8 216290 9 191646 10 52411 10 108715 10 112779 10 201014 11 138870 12 265196 13 227645 14 195317 14 223838 14 280275 14 295597 15 25468 15 246212 16 9179 16 48049 16 132610 17 105687 17 297...
output:
010100001000000000010000100000101000000000000000011001010000111101100000000000110000000101001000100010100010000000000010000000000000000000100100001000100000000000000000100010000000000000000000010000000100000000000000000001000000000000010100000000010000010000101000100000000000000000000000000000010000...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #11:
score: 0
Accepted
time: 356ms
memory: 112152kb
input:
300000 300000 1 54760 2 257942 3 116434 4 5013 4 29020 4 38109 4 275136 5 109601 5 284054 6 228316 6 254970 7 207215 8 19104 8 272726 9 79436 10 292551 11 13982 11 26278 11 96345 12 36575 12 181784 12 208893 13 13219 13 39608 13 44436 13 69629 13 242620 14 5950 14 9745 14 11412 14 57874 14 92103 15 ...
output:
001000010100011100000000000000001001000000000000000001000000000000000000000000000001000000100000101001000000100010001000000010000000100000000000001000000000000010000000000000000000000001000100000000010000000000000000000000000000000100000000000000000011000000010010100000000000000000000000110110000010...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #12:
score: 0
Accepted
time: 106ms
memory: 42004kb
input:
775 299925 386 558 760 764 266 613 557 747 24 368 455 687 256 352 289 400 489 587 115 158 108 281 190 214 293 716 304 731 117 164 290 654 372 375 142 336 489 718 245 399 246 495 584 677 204 263 379 595 67 722 20 644 151 675 155 164 113 420 174 427 667 741 224 614 688 689 279 287 177 200 488 579 50 6...
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #13:
score: 0
Accepted
time: 4ms
memory: 32208kb
input:
6 9 4 6 1 2 2 3 1 5 1 3 1 4 3 6 3 4 4 5
output:
111100101
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #14:
score: -100
Wrong Answer
time: 125ms
memory: 41616kb
input:
1338 299043 185 280 6 434 447 1310 159 486 347 688 54 830 299 363 250 1158 212 1098 433 1102 72 735 215 382 510 1313 408 751 177 888 158 1004 879 1012 216 474 531 586 156 655 143 515 37 1326 255 1230 267 307 60 591 228 1094 166 175 261 1264 282 1022 111 929 331 866 232 1298 927 1124 417 882 775 957 ...
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
result:
wrong answer Deleting vertices 86 and 1104 makes graph disconnected, but participant claims otherwise.