QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442581#8806. Summer Drivingzhaohaikun6 1588ms93932kbC++204.0kb2024-06-15 12:53:272024-06-15 12:53:29

Judging History

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

  • [2024-06-15 12:53:29]
  • 评测
  • 测评结果:6
  • 用时:1588ms
  • 内存:93932kb
  • [2024-06-15 12:53:27]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define mid ((l + r) >> 1)
#define ls num << 1
#define rs ls | 1
#define li ls, l, mid
#define ri rs, mid + 1, r
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = - f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = 3e5 + 10, inf = 1e9;
int n, R, a, b, dfn[N], nfd[N], rdfn[N], dfscnt, dep[N], mn[N], mmn[N], l[N], r[N];//, tl[N], tr[N];
vector <int> v[N], t[N];
void predfs(int x, int fa) {
	mn[x] = x;
	nfd[dfn[x] = ++dfscnt] = x;
	t[dep[x] = dep[fa] + 1].push_back(dfn[x]);
	int mn1 = x, id = x, mn2 = inf;
	for (int i: v[x])
		if (i != fa) {
			predfs(i, x), chkmin(mn[x], mn[i]);
			if (mn[i] < mn1) {
				mn2 = mn1;
				mn1 = mn[i];
				id = i;
			} else chkmin(mn2, mn[i]);
		}
	for (int i: v[x])
		if (i != fa) mmn[i] = id == i ? mn2 : mn1;
	rdfn[x] = dfscnt;
	// if (dep[x] + a <= n) l[x] = lower_bound(all(t[dep[x] + a]), dfn[x]) - t[dep[x] + a].begin(), r[x] = lower_bound(all(t[dep[x] + a]), rdfn[x]) - t[dep[x] + a].begin();
	if (dep[x] + a - 1 <= n) l[x] = lower_bound(all(t[dep[x] + a - 1]), dfn[x]) - t[dep[x] + a - 1].begin(), 
	r[x] = upper_bound(all(t[dep[x] + a - 1]), rdfn[x]) - t[dep[x] + a - 1].begin();
}
int k, p[N];
int tag[N << 2];
void change(int num, int l, int r, int L, int R, int x) {
	if (L <= l && r <= R) return chkmax(tag[num], x), void();
	if (mid >= L) change(li, L, R, x);
	if (mid < R) change(ri, L, R, x);
}
int query(int num, int l, int r, int x) {
	if (l == r) return tag[num];
	if (mid >= x) return max(query(li, x), tag[num]);
	return max(query(ri, x), tag[num]);
}
void dfs(int x, int fa) {
	p[x] = inf;
	int mn1 = inf, id, mn2 = inf;
	for (int i: v[x])
		if (i != fa) {
			dfs(i, x), chkmin(p[x], p[i] + 1);
			if (p[i] < mn1) {
				mn2 = mn1;
				mn1 = p[i];
				id = i;
			} else chkmin(mn2, p[i]);
		}
	bool flag = true;//, gg = true;
	int id1 = 0, id2 = 0;
	int iid1 = 0, iid2 = 0;
	for (int i: v[x])
		if (i != fa) {
			if (l[i] < r[i]) {
				iid2 = iid1;
				iid1 = i;
				// gg = false;
				F(j, l[i], r[i] - 1) {
					int e = nfd[t[dep[x] + a][j]];
					// assert(j < t[dep[x] + a].size());
					// debug << dep[x] + a << endl;
					// if (x == 6) 
					// debug << e << " " << dep[e] << " " << p[e] << " " << dep[e] << " " << query(1, 1, n, dfn[e]) << endl;
					if (p[e] > b && dep[e] > query(1, 1, n, dfn[e])) {
						// if (x == R) debug << i << " " << e << endl;
						id2 = id1, id1 = i;
						break;
					}
				}
			}
			change(1, 1, n, dfn[i], rdfn[i], dep[x] + b - (id == i ? mn2 : mn1) - 1);
		}
	for (int i: v[x])
		if (i != fa) {
			bool flag;
			if (!(iid1 == i ? iid2 : iid1)) flag = mmn[i] <= k;
			else flag = !(id1 == i ? id2 : id1);
			if (flag) change(1, 1, n, dfn[i], rdfn[i], dep[x] + b);
		}
	if (!iid1) flag = mn[x] <= k;
	else flag = !id1;
	if (flag) p[x] = 0;
	// debug << x << " " << flag << endl;// << " " << mn[x] << " " << iid1 << " " << k << endl;
}
bool check() {
	F(i, 1, n * 4) tag[i] = 0;
	dfs(R, 0);
	return p[R] == 0;
}
signed main() {
	read(n), read(R), read(a), read(b);
	if (a <= b) {
		cout << 1;
		return 0;
	}
	F(i, 1, n - 1) {
		int x, y; read(x), read(y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	predfs(R, 0);
	// k = 1;
	// cout << check() << endl;
	// return 0;
	int l = 0, r = n;
	while (l + 1 < r) {
		k = (l + r) >> 1;
		if (check()) r = k;
		else l = k;
	}
	cout << r;
	return 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 1ms
memory: 3660kb

input:

300000 110732 1 1
54285 169439
18968 45543
130988 134682
162292 70081
212010 121474
128140 292466
209394 38279
91706 225569
67647 188578
265505 84279
161782 137098
27472 221980
284973 79104
230628 268631
69945 205947
153720 168119
230161 32244
138981 44376
165008 136947
125742 123375
209131 122038
8...

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

300000 123141 300000 300000
35459 173656
6934 241069
183095 87288
269195 16957
19492 242321
24470 81747
25697 172188
171424 220229
160473 69937
172168 99268
220664 39397
8212 2407
46718 94855
279515 295195
205222 167038
185958 111515
172553 45818
141322 214355
61335 64490
183502 105408
234540 245525...

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3716kb

input:

298765 30225 2 3
265195 252069
113697 255482
227617 218688
279488 136408
179394 139291
86777 211320
255097 13136
68860 173342
178971 175020
278041 278319
285893 289677
194438 44163
56223 283058
110392 123602
20729 89517
152134 176747
121481 243463
297305 139297
244189 117068
181785 39468
154302 1860...

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

299987 224030 2 2
177674 20066
211112 287348
150440 136779
131528 209570
208840 36580
3395 152219
89118 44403
120439 274280
267578 80200
17796 257578
229408 211795
122773 147368
139779 842
94469 299092
211457 29057
9040 117449
216268 88141
40844 98163
183412 221031
230933 237086
147633 135982
282224...

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

2 1 1 2
2 1

output:

1

result:

ok single line: '1'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 4
Accepted
time: 1456ms
memory: 93812kb

input:

300000 226344 300 9
32176 183340
249597 14851
145160 92372
30564 242505
1140 169463
279867 14442
266653 32911
168819 26009
138049 133460
5327 103921
262703 112512
204338 84304
98144 9089
98632 238236
79093 101104
50327 237759
61236 275195
241153 116369
86842 272794
25675 121176
110170 225753
199931 ...

output:

1

result:

ok single line: '1'

Test #7:

score: -4
Wrong Answer
time: 1588ms
memory: 93932kb

input:

299999 92073 2999 11
262905 260944
140896 162257
22797 193473
248112 247445
217760 68693
156294 167586
42291 233355
280566 247233
171395 239795
126564 179464
208554 185755
201665 156263
74786 85307
116366 163760
57326 143227
243541 149484
287792 283934
293052 265098
294245 296048
14582 36967
202999 ...

output:

131

result:

wrong answer 1st lines differ - expected: '245417', found: '131'

Subtask #3:

score: 5
Accepted

Test #18:

score: 5
Accepted
time: 3ms
memory: 11812kb

input:

300 42 3 2
114 268
132 105
187 17
191 127
14 62
162 126
39 143
72 159
199 184
295 138
71 277
293 103
288 54
231 196
57 220
110 117
38 136
295 258
41 76
291 8
59 131
161 278
244 233
81 76
12 236
21 240
228 262
255 159
236 60
277 33
29 123
170 290
89 154
220 139
193 81
31 53
163 77
148 274
181 76
15 2...

output:

83

result:

ok single line: '83'

Test #19:

score: 0
Accepted
time: 0ms
memory: 11896kb

input:

300 178 3 2
277 106
123 105
235 290
273 34
300 180
43 55
239 74
19 138
110 201
295 18
207 97
238 177
114 24
195 219
154 186
151 294
143 291
47 293
33 99
2 46
101 39
109 240
15 256
43 121
205 261
267 257
81 167
82 23
300 182
13 46
195 221
163 17
109 93
144 23
110 17
153 129
91 243
281 74
135 72
145 1...

output:

4

result:

ok single line: '4'

Test #20:

score: 0
Accepted
time: 3ms
memory: 11820kb

input:

300 130 4 2
74 70
137 178
142 56
106 137
154 190
162 96
218 173
261 37
206 72
136 93
293 159
145 94
221 97
76 189
149 282
79 62
258 37
35 20
215 8
143 207
216 38
262 241
37 68
221 258
156 8
213 50
180 238
132 300
256 136
79 281
179 128
177 202
20 229
43 12
290 230
26 105
135 20
146 84
10 184
254 27
...

output:

126

result:

ok single line: '126'

Test #21:

score: 0
Accepted
time: 0ms
memory: 11884kb

input:

300 49 4 2
199 123
264 232
60 265
215 2
226 189
160 11
200 217
194 175
295 203
20 165
203 63
132 127
42 259
170 293
230 269
20 166
141 96
149 210
246 122
5 185
90 156
297 21
300 78
24 94
139 154
268 258
53 15
267 67
221 248
298 154
136 254
192 234
142 170
56 217
90 25
228 216
216 186
61 90
14 221
27...

output:

26

result:

ok single line: '26'

Test #22:

score: 0
Accepted
time: 2ms
memory: 9772kb

input:

300 250 3 1
91 120
269 191
244 235
202 92
3 146
190 210
175 190
243 20
280 75
81 296
179 85
278 283
123 134
98 35
29 65
219 268
242 135
143 238
274 127
99 243
141 231
285 68
269 76
15 61
179 157
165 139
52 49
247 50
151 50
262 161
132 270
224 15
228 144
56 100
293 35
80 98
188 65
263 43
267 234
243 ...

output:

149

result:

ok single line: '149'

Test #23:

score: 0
Accepted
time: 2ms
memory: 9904kb

input:

300 205 3 1
43 211
182 106
31 159
33 141
50 122
33 108
65 275
218 285
263 71
39 211
41 91
264 151
211 286
298 228
84 96
292 176
78 239
107 28
247 265
132 182
225 257
70 58
165 61
162 35
221 23
168 234
279 130
111 261
157 34
61 47
299 97
129 233
247 245
280 60
137 252
241 248
275 91
251 178
288 181
2...

output:

45

result:

ok single line: '45'

Test #24:

score: 0
Accepted
time: 2ms
memory: 13924kb

input:

300 151 10 4
106 66
88 78
279 12
92 142
298 168
98 117
8 108
104 192
50 216
227 176
77 297
149 195
94 11
72 69
235 267
261 11
131 35
115 146
140 73
132 251
185 145
29 193
52 90
287 39
261 300
24 206
223 59
270 35
225 35
32 95
184 244
52 164
276 118
220 268
249 251
187 217
288 71
297 34
171 198
178 2...

output:

2

result:

ok single line: '2'

Test #25:

score: 0
Accepted
time: 2ms
memory: 9924kb

input:

300 203 300 10
2 182
179 26
120 101
281 271
236 75
260 242
121 271
32 66
277 14
98 47
152 83
231 39
145 93
23 127
203 76
76 252
65 31
33 62
60 201
154 147
42 83
13 203
203 2
265 292
96 30
23 85
23 64
220 30
189 277
296 44
63 110
107 202
61 93
134 286
65 122
133 241
152 142
97 84
209 202
267 47
255 8...

output:

1

result:

ok single line: '1'

Test #26:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

123 33 3 3
63 85
6 68
37 58
78 86
111 69
36 110
115 56
41 63
112 15
99 61
55 96
123 88
45 16
37 54
95 41
54 24
26 108
40 83
60 36
83 25
71 19
83 7
56 53
123 30
46 93
20 104
99 23
52 84
49 31
110 109
53 97
33 18
90 94
80 3
82 58
108 100
97 14
32 99
8 60
54 119
101 35
23 48
42 8
54 5
10 73
35 18
113 1...

output:

1

result:

ok single line: '1'

Test #27:

score: 0
Accepted
time: 0ms
memory: 11840kb

input:

231 165 100 50
114 20
131 183
182 20
31 36
210 93
13 188
175 5
154 63
48 24
205 90
146 153
129 186
156 106
27 82
49 198
89 42
111 146
203 142
87 20
98 188
65 63
196 118
15 102
137 75
101 67
143 160
130 197
186 209
50 172
47 224
4 220
59 41
148 16
32 182
131 90
87 225
177 77
149 30
93 33
51 106
185 1...

output:

1

result:

ok single line: '1'

Test #28:

score: 0
Accepted
time: 2ms
memory: 12000kb

input:

300 11 30 16
90 227
152 287
67 39
165 50
242 139
278 177
51 148
129 214
94 124
37 201
53 254
84 202
267 183
95 171
251 32
45 170
161 275
272 268
209 49
34 272
106 75
223 285
42 72
130 138
91 263
230 158
31 59
80 209
262 45
136 131
162 121
297 287
32 207
228 171
112 58
273 70
173 176
169 34
155 54
37...

output:

29

result:

ok single line: '29'

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #29:

score: 3
Accepted
time: 9ms
memory: 14088kb

input:

3000 63 3 2
2155 250
1688 831
522 631
1755 1764
55 2251
2127 1756
1135 387
600 1437
182 1020
1802 1849
399 2974
1809 574
402 2032
2147 2561
1186 830
829 2804
1086 1237
82 414
892 375
107 2688
1857 1972
1162 324
1758 1763
1255 918
1553 908
849 1670
132 2126
2503 861
1906 1836
305 1063
922 6
2068 1435...

output:

878

result:

ok single line: '878'

Test #30:

score: 0
Accepted
time: 7ms
memory: 12172kb

input:

3000 528 3 2
2749 507
78 1098
1114 832
608 2375
2044 319
1549 1782
2146 1096
2728 817
1542 394
1362 2837
2714 2424
141 1693
190 2792
424 2422
2891 1525
1796 1932
2241 1427
790 1721
1044 1909
1240 2843
2964 1850
1587 2274
1249 1126
1 1689
2558 994
2911 2148
1160 1580
2530 2574
1402 1723
961 1518
2520...

output:

4

result:

ok single line: '4'

Test #31:

score: 0
Accepted
time: 4ms
memory: 14064kb

input:

3000 458 4 2
943 1128
2440 1236
1649 2508
2922 420
1540 1811
1710 566
1260 668
2124 858
78 373
551 1017
1611 1744
536 104
1999 2934
2391 354
765 675
301 316
301 1613
2919 2533
2604 301
443 1540
2287 1580
397 1970
1925 1439
2478 2414
2189 1169
521 2182
1700 163
2575 334
477 1728
581 332
45 2170
1485 ...

output:

1318

result:

ok single line: '1318'

Test #32:

score: 0
Accepted
time: 8ms
memory: 14224kb

input:

3000 2841 4 2
1502 2819
421 217
1423 1914
1968 2313
1207 544
2752 1319
2459 1345
2192 2421
1320 1368
2936 971
637 1964
1328 1901
1568 1868
1544 1357
308 2198
1883 2064
978 685
336 2521
2173 1402
1288 1166
1514 684
2369 771
1339 738
1446 2786
1060 1543
375 1947
1756 1912
1397 288
609 2230
1015 1187
2...

output:

174

result:

ok single line: '174'

Test #33:

score: -3
Wrong Answer
time: 8ms
memory: 14164kb

input:

3000 2364 3 1
1809 381
674 1824
2549 125
1469 1465
1144 2486
1177 862
2559 1927
1211 36
630 739
2926 1555
1169 2479
2984 2956
1669 1009
398 2796
469 991
1886 2628
2770 2725
1216 1394
703 76
2016 1162
722 1840
78 2793
326 1057
918 1887
1291 2478
1160 1312
2990 801
2969 212
1727 2594
1727 1862
2541 62...

output:

2010

result:

wrong answer 1st lines differ - expected: '2143', found: '2010'

Subtask #5:

score: 0
Wrong Answer

Test #49:

score: 4
Accepted
time: 406ms
memory: 20872kb

input:

100000 20749 3 2
89778 51257
2293 75317
20142 42260
55350 69024
2419 90402
2248 71914
60607 94307
33933 57799
79884 93934
9788 53542
18109 28742
7700 93763
12102 78825
34580 61577
84344 12887
63610 12371
30988 75638
47533 66209
95296 22495
12638 545
36347 57495
41813 49592
60342 1881
38899 62345
524...

output:

43056

result:

ok single line: '43056'

Test #50:

score: 0
Accepted
time: 371ms
memory: 20580kb

input:

100000 81436 3 2
30487 98338
75456 42340
35081 95919
14744 79324
12767 72910
10330 15285
18425 40190
49306 55115
27041 60644
82901 10649
43365 29415
57822 86861
83007 50520
39798 89642
44146 63575
29824 89809
23549 45972
89791 83570
13656 1315
63396 74190
21244 80244
90922 97110
38966 92339
84884 89...

output:

717

result:

ok single line: '717'

Test #51:

score: 0
Accepted
time: 392ms
memory: 20508kb

input:

100000 8852 4 2
40452 57256
17799 88040
60724 53958
13290 90136
19267 49330
97135 48815
91159 71145
11677 334
6176 11175
2311 36476
80261 78319
22343 42921
53692 9431
20138 8540
15962 57516
66603 41779
22916 82799
36377 26000
46797 3889
5764 3600
76457 13146
41675 46067
65577 93967
3461 31914
46191 ...

output:

66085

result:

ok single line: '66085'

Test #52:

score: 0
Accepted
time: 430ms
memory: 20904kb

input:

100000 16035 4 2
43071 56048
63171 4393
98259 47823
2561 96442
9238 88690
85973 58025
9308 88080
16242 96064
88566 55956
57022 90692
84895 82151
27964 28817
24774 35654
35624 93885
37408 43501
89095 11303
1737 8666
378 67623
56302 11639
22263 32297
12188 72428
49974 80854
29579 370
70340 55421
4511 ...

output:

13134

result:

ok single line: '13134'

Test #53:

score: 0
Accepted
time: 406ms
memory: 22004kb

input:

100000 85235 3 1
94738 24340
59327 27917
90855 27869
97393 55723
50462 24028
27405 59525
40629 84195
41269 21311
97793 12448
94822 90533
96359 70118
59964 12798
51098 68286
58527 7816
41817 19034
10924 54535
63191 97115
60743 79349
6864 76498
29085 92310
8063 41260
11214 91868
23225 2976
50822 99018...

output:

86829

result:

ok single line: '86829'

Test #54:

score: 0
Accepted
time: 406ms
memory: 22112kb

input:

100000 96572 3 1
36159 41653
67667 34037
37976 63963
45201 5393
52221 59416
54961 13650
28764 99209
60804 67606
48624 79765
41041 83510
51667 65582
53730 45676
22269 64403
52565 21021
64941 4761
62855 69936
67203 18060
91572 33888
52593 86981
38287 22045
72710 6674
19970 36871
12501 91926
14428 9425...

output:

12008

result:

ok single line: '12008'

Test #55:

score: 0
Accepted
time: 352ms
memory: 21348kb

input:

100000 73324 10 4
71933 28912
87834 88149
44971 99521
60861 82846
97055 92782
56244 87280
53155 84157
70530 70324
79371 71634
21639 40110
75095 53060
6988 96059
21201 57449
65138 12755
88230 54355
87152 56089
86570 76587
79256 65685
16310 13946
41916 10874
9161 88963
90203 58683
76300 29464
25230 30...

output:

513

result:

ok single line: '513'

Test #56:

score: 0
Accepted
time: 242ms
memory: 21908kb

input:

100000 15636 100000 10
10243 50231
32391 7992
18149 2934
33787 51982
96445 22322
41361 80285
17777 24611
69149 49364
87021 54306
89564 43531
90973 83603
85869 90213
27390 88410
38427 49151
77811 41575
32541 86212
92924 21286
47549 65738
76763 15623
17786 10339
32880 76070
9809 67114
91819 43885
7140...

output:

1

result:

ok single line: '1'

Test #57:

score: 0
Accepted
time: 358ms
memory: 22176kb

input:

100000 42996 20 10
74902 50663
7097 23701
45735 7288
52375 46377
46724 63127
89073 24467
29104 28729
83469 85669
70860 88962
78797 72790
27570 86063
24686 20963
90850 57413
17431 29758
84798 67397
74951 85193
37009 12044
56862 33692
23929 61577
18914 38454
58446 32853
69649 68901
55638 59986
47751 1...

output:

221

result:

ok single line: '221'

Test #58:

score: 0
Accepted
time: 378ms
memory: 20440kb

input:

100000 98739 100 10
85414 42813
17848 77599
42506 71989
1918 745
9097 91249
79539 71491
71938 77961
66338 99594
19970 52870
38371 91469
69665 44311
13354 45803
56738 89880
46844 51870
38831 48646
37471 66852
2177 16313
35195 71674
8625 70549
1856 78239
9309 43203
4214 95780
29103 47895
69129 78296
4...

output:

14017

result:

ok single line: '14017'

Test #59:

score: -4
Wrong Answer
time: 291ms
memory: 20324kb

input:

100000 29573 10000 10
54397 69025
83525 16322
69843 91831
18296 65353
43293 19327
70856 30469
80150 62236
40232 32171
68933 90628
66837 2965
54776 47328
62998 65584
23455 70312
34594 26099
90702 38631
99042 75615
83802 53660
60219 72548
22411 34554
71451 67910
31284 17953
55582 86186
80488 79094
180...

output:

1

result:

wrong answer 1st lines differ - expected: '4314', found: '1'

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%