QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#287707#1256. Delete Two Vertices AgainDualqwqWA 607ms274984kbC++203.8kb2023-12-20 21:56:202023-12-20 21:56:21

Judging History

你现在查看的是最新测评结果

  • [2023-12-20 21:56:21]
  • 评测
  • 测评结果:WA
  • 用时:607ms
  • 内存:274984kb
  • [2023-12-20 21:56:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5,M = 6e5 + 5,Lg = 19;
int n,m;
int fir[N],nxt[M],to[M],ect = 1;
inline void addedge(int u1,int v1) {
	nxt[++ect] = fir[u1];fir[u1] = ect;to[ect] = v1;
}

int U[M],V[M];
vector<int> par[N],G[N];
bool vst[N];
int dep[N];

const int Sz = M << 5;
int rt[N],rt2[N],lc[Sz],rc[Sz],sum[Sz],tot = 0;
void insert(int &k,int l,int r,int pos,int v) {
	if(!k) k = ++tot;
	if(l == r) { sum[k] += v;return;}
	int mid = l + r >> 1;
	if(pos <= mid) insert(lc[k],l,mid,pos,v);
	else insert(rc[k],mid + 1,r,pos,v);
	sum[k] = sum[lc[k]] + sum[rc[k]];
}
int Merge(int x,int y,int l,int r) {
	if(!x || !y) return x + y;
	int p = ++tot,mid = l + r >> 1;
	sum[p] = sum[x] + sum[y];
	if(l == r) return p;
	// sum[p] = sum[x] + sum[y];
	lc[p] = Merge(lc[x],lc[y],l,mid);
	rc[p] = Merge(rc[x],rc[y],mid + 1,r);
	// sum[p] = sum[lc[p]] + sum[rc[p]];
	return p;
}
int Query(int k,int l,int r,int x,int y) {
	if(!k || x > y) return 0;
	if(x <= l && r <= y) return sum[k];
	int mid = l + r >> 1;
	if(y <= mid) return Query(lc[k],l,mid,x,y);
	else if(x > mid) return Query(rc[k],mid + 1,r,x,y);
	else return Query(lc[k],l,mid,x,y) + Query(rc[k],mid + 1,r,x,y);
}
int anc[Lg][N];
int dfn[N],sze[N];
inline bool isanc(int x,int y) { return dfn[x] <= dfn[y] && dfn[y] < dfn[x] + sze[x];}
void dfs(int x) {
	// printf("dep[%d]=%d\n",x,dep[x]);
	vst[x] = true;sze[x] = 1;//printf("anc[0][%d]=%d,%d\n",x,anc[0][x],dep[x]);
	for(int i = 1;i < Lg;i++) anc[i][x] = anc[i - 1][anc[i - 1][x]];
	// for(auto y : par[x])
	// 	if(vst[y]) insert(rt[x],1,n,dep[y],1),printf("path:%d,%d\n",x,y);
	dfn[x] = ++dfn[0];
	for(int i = fir[x],y;y = to[i],i;i = nxt[i])
		if(!vst[y]) {

			G[x].push_back(y);
			anc[0][y] = x;
			dep[y] = dep[x] + 1;
			dfs(y);sze[x] += sze[y];
			// rt[x] = Merge(rt[x],rt[y]);
			// printf("%d->%d\n",x,y);
		}
}
inline int Qsub(int x,int lim) {
	int res = 0;
	for(int i = 1;i <= n;i++)
		if(isanc(x,i))
			for(auto j : par[i])
				if(dep[j] <= lim) ++res;
	return res;
}
void dfs1(int x) {	
	for(auto y : par[x]) if(dep[y] < dep[x]) insert(rt[x],1,n,dep[y],1),insert(rt2[x],1,n,dep[y],1);

	for(auto y : G[x]) dfs1(y),rt[x] = Merge(rt[x],rt[y],1,n);
}
inline int jump(int x,int y) {
	for(int i = Lg - 1;i >= 0;i--)
		if(dep[anc[i][x]] > dep[y]) x = anc[i][x];
	return x;
}
inline bool Ask(int u,int v) {
	if(dep[u] > dep[v]) swap(u,v);
	int pp = jump(v,u);
	// printf("jp:%d,%d,%d\n",u,v,pp);
	if(u != 1) {
		for(auto t : G[u]) {
			// printf("t:%d,%d,%d\n",t,Query(rt[t],1,n,1,dep[u] - 1),Qsub(t,dep[u] - 1));
			if(t != pp && !Query(rt[t],1,n,1,dep[u] - 1)) return false;
		}
		
	}
	else {
		if(G[u].size() > 2) return false;
		if(G[u].size() == 2 && (pp != v || G[v].size())) return false;
	}
	// if(u == 6 && v == 4) {
	// 	puts("d1");
	// 	printf("v1,v2:%d,%d,%d,%d,%d,%d\n",pp,v,Query(rt[pp],1,n,1,dep[u] - 1),Query(rt[v],1,n,1,dep[u] - 1),Qsub(pp,dep[u] - 1),Qsub(v,dep[u] - 1));
	// }
	if(pp != v && sze[pp] != 1 && u != 1 && !(Query(rt[pp],1,n,1,dep[u] - 1) - Query(rt[v],1,n,1,dep[u] - 1))) return false;
	// if(u == 6 && v == 4) puts("d2");

	for(auto t : G[v]) if(sze[t] != n - 2) {
		int val = Query(rt[t],1,n,1,dep[v] - 1) - Query(rt[t],1,n,dep[u],dep[u]);
		if(!val) return false;
		// if(sze[t] != n - 2 && !Query(rt[t],1,n,1,dep[v] - 1)) return false;
	}
	return true;
}
int main() {
	cin >> n >> m;
	for(int i = 1;i <= m;i++) {
		cin >> U[i] >> V[i],addedge(U[i],V[i]),addedge(V[i],U[i]);
		par[U[i]].push_back(V[i]);
		par[V[i]].push_back(U[i]);
	}
	dep[1] = 1;dfs(1);dfs1(1);
	// Ask(4,2);
	// cout << "===========" << endl;
	for(int i = 1;i <= m;i++)
		if(Ask(U[i],V[i])) putchar('1'); else putchar('0');
	return 0;
}
/*
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
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 46768kb

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: 0ms
memory: 48752kb

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: 46652kb

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: 0ms
memory: 46648kb

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: 50720kb

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: 0ms
memory: 48616kb

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: 607ms
memory: 274904kb

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: 555ms
memory: 274884kb

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: 553ms
memory: 274892kb

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: 552ms
memory: 274856kb

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: 577ms
memory: 274984kb

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: 225ms
memory: 78852kb

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: 0ms
memory: 46708kb

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: 254ms
memory: 78964kb

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 838 and 1024 makes graph connected, but participant claims otherwise.