#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
int n, m;
vector<int> cnt, ans;
vector<vector<tuple<int, int, int>>> g;
void dfs(int u, int p, int l, int r) {
for (int i = l; i <= r; i++) cnt[i]++;
for (int i = 1; i <= m; i++) ans[u] += cnt[i] > 0;
for (auto [v, lx, rx]: g[u]) {
if (v != p) {
dfs(v, u, lx, rx);
}
}
for (int i = l; i <= r; i++) cnt[i]--;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
g.assign(n + 1, {});
ans.assign(n + 1, 0);
cnt.assign(m + 1, 0);
for (int i = 1; i < n; i++) {
int u, v, l, r;
cin >> u >> v >> l >> r;
g[u].emplace_back(v, l, r);
g[v].emplace_back(u, l, r);
}
dfs(1, 0, 1, 0);
for (int i = 2; i <= n; i++) cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Runtime error |
223 ms |
524288 KB |
Execution killed with signal 9 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1827 ms |
7548 KB |
Output is correct |
26 |
Correct |
1818 ms |
7560 KB |
Output is correct |
27 |
Correct |
1365 ms |
7584 KB |
Output is correct |
28 |
Correct |
1371 ms |
7816 KB |
Output is correct |
29 |
Correct |
1228 ms |
7792 KB |
Output is correct |
30 |
Correct |
1207 ms |
7688 KB |
Output is correct |
31 |
Correct |
153 ms |
1240 KB |
Output is correct |
32 |
Correct |
149 ms |
1308 KB |
Output is correct |
33 |
Correct |
149 ms |
1356 KB |
Output is correct |
34 |
Correct |
149 ms |
1292 KB |
Output is correct |
35 |
Correct |
1826 ms |
4492 KB |
Output is correct |
36 |
Correct |
1904 ms |
4676 KB |
Output is correct |
37 |
Correct |
1514 ms |
4564 KB |
Output is correct |
38 |
Correct |
1412 ms |
4924 KB |
Output is correct |
39 |
Correct |
1313 ms |
4640 KB |
Output is correct |
40 |
Correct |
1323 ms |
4596 KB |
Output is correct |
41 |
Correct |
152 ms |
932 KB |
Output is correct |
42 |
Correct |
149 ms |
980 KB |
Output is correct |
43 |
Correct |
1831 ms |
4208 KB |
Output is correct |
44 |
Correct |
1839 ms |
4196 KB |
Output is correct |
45 |
Correct |
1371 ms |
4372 KB |
Output is correct |
46 |
Correct |
1382 ms |
4308 KB |
Output is correct |
47 |
Correct |
1227 ms |
4180 KB |
Output is correct |
48 |
Correct |
1201 ms |
4168 KB |
Output is correct |
49 |
Correct |
149 ms |
920 KB |
Output is correct |
50 |
Correct |
154 ms |
928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1827 ms |
7548 KB |
Output is correct |
26 |
Correct |
1818 ms |
7560 KB |
Output is correct |
27 |
Correct |
1365 ms |
7584 KB |
Output is correct |
28 |
Correct |
1371 ms |
7816 KB |
Output is correct |
29 |
Correct |
1228 ms |
7792 KB |
Output is correct |
30 |
Correct |
1207 ms |
7688 KB |
Output is correct |
31 |
Correct |
153 ms |
1240 KB |
Output is correct |
32 |
Correct |
149 ms |
1308 KB |
Output is correct |
33 |
Correct |
149 ms |
1356 KB |
Output is correct |
34 |
Correct |
149 ms |
1292 KB |
Output is correct |
35 |
Correct |
1826 ms |
4492 KB |
Output is correct |
36 |
Correct |
1904 ms |
4676 KB |
Output is correct |
37 |
Correct |
1514 ms |
4564 KB |
Output is correct |
38 |
Correct |
1412 ms |
4924 KB |
Output is correct |
39 |
Correct |
1313 ms |
4640 KB |
Output is correct |
40 |
Correct |
1323 ms |
4596 KB |
Output is correct |
41 |
Correct |
152 ms |
932 KB |
Output is correct |
42 |
Correct |
149 ms |
980 KB |
Output is correct |
43 |
Correct |
1831 ms |
4208 KB |
Output is correct |
44 |
Correct |
1839 ms |
4196 KB |
Output is correct |
45 |
Correct |
1371 ms |
4372 KB |
Output is correct |
46 |
Correct |
1382 ms |
4308 KB |
Output is correct |
47 |
Correct |
1227 ms |
4180 KB |
Output is correct |
48 |
Correct |
1201 ms |
4168 KB |
Output is correct |
49 |
Correct |
149 ms |
920 KB |
Output is correct |
50 |
Correct |
154 ms |
928 KB |
Output is correct |
51 |
Execution timed out |
3051 ms |
11472 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
456 KB |
Output is correct |
5 |
Correct |
2 ms |
464 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Runtime error |
223 ms |
524288 KB |
Execution killed with signal 9 |
26 |
Halted |
0 ms |
0 KB |
- |