QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50761 | #1256. Delete Two Vertices Again | tricyzhkx | WA | 463ms | 112256kb | C++14 | 3.5kb | 2022-09-29 10:18:51 | 2022-09-29 10:18:52 |
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,top[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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 32156kb
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: 12ms
memory: 32080kb
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: 32112kb
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: 11ms
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: 0ms
memory: 31992kb
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: 3ms
memory: 32208kb
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: 463ms
memory: 112028kb
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: 399ms
memory: 112180kb
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: 391ms
memory: 112216kb
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: 390ms
memory: 112140kb
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: 399ms
memory: 112256kb
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: 42008kb
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: 9ms
memory: 32164kb
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: 0
Accepted
time: 106ms
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:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #15:
score: 0
Accepted
time: 107ms
memory: 43244kb
input:
1095 299756 82 328 198 226 230 574 34 842 168 687 277 772 595 929 524 930 478 700 630 1002 455 1061 620 689 26 303 861 875 221 935 939 1061 267 994 61 431 292 607 269 925 355 500 122 437 639 683 160 997 310 658 511 1044 65 643 981 1036 31 1072 701 992 170 741 17 392 521 673 863 1094 202 745 170 725 ...
output:
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111...
result:
ok OK. Jury's and participant's answers coincide. We don't know if they are both correct or both wrong.
Test #16:
score: 0
Accepted
time: 128ms
memory: 106432kb
input:
200001 299999 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
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 #17:
score: 0
Accepted
time: 143ms
memory: 105584kb
input:
200001 299999 200001 200000 200000 199999 199999 199998 199998 199997 199997 199996 199996 199995 199995 199994 199994 199993 199993 199992 199992 199991 199991 199990 199990 199989 199989 199988 199988 199987 199987 199986 199986 199985 199985 199984 199984 199983 199983 199982 199982 199981 199981...
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 #18:
score: 0
Accepted
time: 285ms
memory: 106888kb
input:
200001 299999 153281 180117 180117 111295 111295 169234 169234 169877 169877 150276 150276 122865 122865 10968 10968 69558 69558 168830 168830 16865 16865 47507 47507 89231 89231 199657 199657 118035 118035 67168 67168 143671 143671 133752 133752 192407 192407 19033 19033 3951 3951 62468 62468 12207...
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 #19:
score: 0
Accepted
time: 138ms
memory: 106492kb
input:
200001 300000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
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 #20:
score: 0
Accepted
time: 132ms
memory: 105832kb
input:
200001 300000 200001 200000 200000 199999 199999 199998 199998 199997 199997 199996 199996 199995 199995 199994 199994 199993 199993 199992 199992 199991 199991 199990 199990 199989 199989 199988 199988 199987 199987 199986 199986 199985 199985 199984 199984 199983 199983 199982 199982 199981 199981...
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 #21:
score: 0
Accepted
time: 319ms
memory: 106168kb
input:
200001 300000 25308 168155 168155 6093 6093 111775 111775 153790 153790 120592 120592 54450 54450 129380 129380 31320 31320 158894 158894 105631 105631 120833 120833 100011 100011 88104 88104 21763 21763 77260 77260 129405 129405 127327 127327 27337 27337 65469 65469 55578 55578 31258 31258 18356 18...
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 #22:
score: 0
Accepted
time: 233ms
memory: 105176kb
input:
160001 300000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
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 #23:
score: 0
Accepted
time: 267ms
memory: 105876kb
input:
160001 300000 160001 160000 160000 159999 159999 159998 159998 159997 159997 159996 159996 159995 159995 159994 159994 159993 159993 159992 159992 159991 159991 159990 159990 159989 159989 159988 159988 159987 159987 159986 159986 159985 159985 159984 159984 159983 159983 159982 159982 159981 159981...
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 #24:
score: 0
Accepted
time: 412ms
memory: 105656kb
input:
160001 300000 100814 81998 81998 47964 47964 15162 15162 99833 99833 91815 91815 91064 91064 44409 44409 7755 7755 43827 43827 97797 97797 96617 96617 128251 128251 116798 116798 61949 61949 14165 14165 35036 35036 12130 12130 55984 55984 119544 119544 15032 15032 153671 153671 9090 9090 56365 56365...
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 #25:
score: -100
Wrong Answer
time: 175ms
memory: 100504kb
input:
205014 299995 1 2 3 2 4 2 1 5 6 5 7 6 1 8 10 8 10 9 1 11 12 11 13 11 13 12 1 14 15 14 16 14 17 14 1 18 19 18 20 19 21 18 1 22 24 22 24 23 25 22 1 26 27 26 28 26 28 27 29 26 1 30 31 30 32 30 33 31 1 34 35 34 36 35 37 35 1 38 40 38 40 39 41 39 1 42 43 42 44 42 44 43 45 43 1 46 48 46 49 46 49 47 1 50 5...
output:
000001001000100000010001000010000100000001000010001000010100001000010100010100010001000000001000100001010000101001000001010001001000011000010001000001100000000100010000011010000010010010100001011000000010000100000100000100000000010000010000100000100100000100000101000010100001000010000000000100001000...
result:
wrong answer Deleting vertices 29869 and 29865 makes graph connected, but participant claims otherwise.