#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define oo 2e9
#define pii pair<ll, int>
const int MAX = 1e5 + 5, LOGMAX = 31, treesize = MAX * LOGMAX;
int n, m;
vector<array<int, 3>> g[MAX];
pii tree[treesize];
int L[treesize], R[treesize], lazy[treesize];
int nxt = 2;
void relax(int node, int l, int r){
if(!lazy[node]) return;
tree[node].first += lazy[node];
if(l == r){
lazy[node] = 0;
return;
}
int mid = (l + r) / 2;
if(!L[node]){
L[node] = nxt++;
tree[L[node]] = {0, mid - l + 1};
}
if(!R[node]){
R[node] = nxt++;
tree[R[node]] = {0, r - mid};
}
lazy[L[node]] += lazy[node];
lazy[R[node]] += lazy[node];
lazy[node] = 0;
}
pii combine(pii a, pii b){
if(a.first == b.first){
return {a.first, a.second + b.second};
}
return min(a, b);
}
void update(int node, int l, int r, int ul, int ur, int val){
relax(node, l, r);
if(ur < l || r < ul) return;
if(ul <= l && r <= ur){
lazy[node] += val;
relax(node, l, r);
return;
}
int mid = (l + r) / 2;
if(!L[node]){
L[node] = nxt++;
tree[L[node]] = {0, mid - l + 1};
}
if(!R[node]){
R[node] = nxt++;
tree[R[node]] = {0, r - mid};
}
update(L[node], l, mid, ul, ur, val);
update(R[node], mid + 1, r, ul, ur, val);
tree[node] = combine(tree[L[node]], tree[R[node]]);
}
int ans[MAX];
void dfs(int node, int p, int l, int r){
if(node != 1){
update(1, 1, m, l, r, 1);
}
if(tree[1].first == 0){
ans[node] = m - tree[1].second;
}
else{
ans[node] = m;
}
for(auto to : g[node]){
if(p == to[0]) continue;
dfs(to[0], node, to[1], to[2]);
}
if(node != 1){
update(1, 1, m, l, r, -1);
}
}
int main(){
cin >> n >> m;
for(int i = 1; i < n; i++){
int a, b, l, r; cin >> a >> b >> l >> r;
g[a].push_back({b, l, r});
g[b].push_back({a, l, r});
}
tree[1] = {0, m};
dfs(1, 1, 0, 0);
for(int i = 2; i <= n; i++){
cout << ans[i] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
6180 KB |
Output is correct |
3 |
Correct |
4 ms |
5976 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5976 KB |
Output is correct |
6 |
Correct |
3 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5720 KB |
Output is correct |
10 |
Correct |
3 ms |
5720 KB |
Output is correct |
11 |
Correct |
3 ms |
5720 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
3 ms |
5720 KB |
Output is correct |
14 |
Correct |
3 ms |
5720 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
2 ms |
5720 KB |
Output is correct |
17 |
Correct |
3 ms |
5720 KB |
Output is correct |
18 |
Correct |
3 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
3 ms |
5720 KB |
Output is correct |
21 |
Correct |
3 ms |
5720 KB |
Output is correct |
22 |
Correct |
3 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
6180 KB |
Output is correct |
3 |
Correct |
4 ms |
5976 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5976 KB |
Output is correct |
6 |
Correct |
3 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5720 KB |
Output is correct |
10 |
Correct |
3 ms |
5720 KB |
Output is correct |
11 |
Correct |
3 ms |
5720 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
3 ms |
5720 KB |
Output is correct |
14 |
Correct |
3 ms |
5720 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
2 ms |
5720 KB |
Output is correct |
17 |
Correct |
3 ms |
5720 KB |
Output is correct |
18 |
Correct |
3 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
3 ms |
5720 KB |
Output is correct |
21 |
Correct |
3 ms |
5720 KB |
Output is correct |
22 |
Correct |
3 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
25 |
Correct |
4 ms |
5976 KB |
Output is correct |
26 |
Correct |
5 ms |
5976 KB |
Output is correct |
27 |
Correct |
7 ms |
9560 KB |
Output is correct |
28 |
Correct |
7 ms |
9560 KB |
Output is correct |
29 |
Correct |
4 ms |
8280 KB |
Output is correct |
30 |
Correct |
4 ms |
8280 KB |
Output is correct |
31 |
Correct |
5 ms |
9048 KB |
Output is correct |
32 |
Correct |
5 ms |
9052 KB |
Output is correct |
33 |
Correct |
5 ms |
9048 KB |
Output is correct |
34 |
Correct |
5 ms |
9048 KB |
Output is correct |
35 |
Correct |
5 ms |
5720 KB |
Output is correct |
36 |
Correct |
4 ms |
5724 KB |
Output is correct |
37 |
Correct |
6 ms |
9560 KB |
Output is correct |
38 |
Correct |
6 ms |
9560 KB |
Output is correct |
39 |
Correct |
5 ms |
8280 KB |
Output is correct |
40 |
Correct |
5 ms |
8280 KB |
Output is correct |
41 |
Correct |
5 ms |
9180 KB |
Output is correct |
42 |
Correct |
5 ms |
9048 KB |
Output is correct |
43 |
Correct |
4 ms |
5720 KB |
Output is correct |
44 |
Correct |
4 ms |
5724 KB |
Output is correct |
45 |
Correct |
6 ms |
9304 KB |
Output is correct |
46 |
Correct |
6 ms |
9560 KB |
Output is correct |
47 |
Correct |
5 ms |
8284 KB |
Output is correct |
48 |
Correct |
4 ms |
8280 KB |
Output is correct |
49 |
Correct |
5 ms |
9048 KB |
Output is correct |
50 |
Correct |
6 ms |
9048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
6180 KB |
Output is correct |
3 |
Correct |
4 ms |
5976 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5976 KB |
Output is correct |
6 |
Correct |
3 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5720 KB |
Output is correct |
10 |
Correct |
3 ms |
5720 KB |
Output is correct |
11 |
Correct |
3 ms |
5720 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
3 ms |
5720 KB |
Output is correct |
14 |
Correct |
3 ms |
5720 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
2 ms |
5720 KB |
Output is correct |
17 |
Correct |
3 ms |
5720 KB |
Output is correct |
18 |
Correct |
3 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
3 ms |
5720 KB |
Output is correct |
21 |
Correct |
3 ms |
5720 KB |
Output is correct |
22 |
Correct |
3 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
25 |
Correct |
79 ms |
9808 KB |
Output is correct |
26 |
Correct |
80 ms |
9888 KB |
Output is correct |
27 |
Correct |
96 ms |
12880 KB |
Output is correct |
28 |
Correct |
101 ms |
12848 KB |
Output is correct |
29 |
Correct |
66 ms |
12880 KB |
Output is correct |
30 |
Correct |
67 ms |
12880 KB |
Output is correct |
31 |
Correct |
10 ms |
9048 KB |
Output is correct |
32 |
Correct |
9 ms |
9048 KB |
Output is correct |
33 |
Correct |
10 ms |
9048 KB |
Output is correct |
34 |
Correct |
10 ms |
9048 KB |
Output is correct |
35 |
Correct |
80 ms |
8020 KB |
Output is correct |
36 |
Correct |
78 ms |
7960 KB |
Output is correct |
37 |
Correct |
93 ms |
11056 KB |
Output is correct |
38 |
Correct |
93 ms |
11120 KB |
Output is correct |
39 |
Correct |
70 ms |
11088 KB |
Output is correct |
40 |
Correct |
65 ms |
10832 KB |
Output is correct |
41 |
Correct |
10 ms |
8792 KB |
Output is correct |
42 |
Correct |
11 ms |
8792 KB |
Output is correct |
43 |
Correct |
79 ms |
7760 KB |
Output is correct |
44 |
Correct |
78 ms |
7876 KB |
Output is correct |
45 |
Correct |
94 ms |
10832 KB |
Output is correct |
46 |
Correct |
92 ms |
10832 KB |
Output is correct |
47 |
Correct |
64 ms |
10684 KB |
Output is correct |
48 |
Correct |
65 ms |
10692 KB |
Output is correct |
49 |
Correct |
11 ms |
8536 KB |
Output is correct |
50 |
Correct |
10 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
6180 KB |
Output is correct |
3 |
Correct |
4 ms |
5976 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5976 KB |
Output is correct |
6 |
Correct |
3 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5720 KB |
Output is correct |
10 |
Correct |
3 ms |
5720 KB |
Output is correct |
11 |
Correct |
3 ms |
5720 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
3 ms |
5720 KB |
Output is correct |
14 |
Correct |
3 ms |
5720 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
2 ms |
5720 KB |
Output is correct |
17 |
Correct |
3 ms |
5720 KB |
Output is correct |
18 |
Correct |
3 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
3 ms |
5720 KB |
Output is correct |
21 |
Correct |
3 ms |
5720 KB |
Output is correct |
22 |
Correct |
3 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
25 |
Correct |
79 ms |
9808 KB |
Output is correct |
26 |
Correct |
80 ms |
9888 KB |
Output is correct |
27 |
Correct |
96 ms |
12880 KB |
Output is correct |
28 |
Correct |
101 ms |
12848 KB |
Output is correct |
29 |
Correct |
66 ms |
12880 KB |
Output is correct |
30 |
Correct |
67 ms |
12880 KB |
Output is correct |
31 |
Correct |
10 ms |
9048 KB |
Output is correct |
32 |
Correct |
9 ms |
9048 KB |
Output is correct |
33 |
Correct |
10 ms |
9048 KB |
Output is correct |
34 |
Correct |
10 ms |
9048 KB |
Output is correct |
35 |
Correct |
80 ms |
8020 KB |
Output is correct |
36 |
Correct |
78 ms |
7960 KB |
Output is correct |
37 |
Correct |
93 ms |
11056 KB |
Output is correct |
38 |
Correct |
93 ms |
11120 KB |
Output is correct |
39 |
Correct |
70 ms |
11088 KB |
Output is correct |
40 |
Correct |
65 ms |
10832 KB |
Output is correct |
41 |
Correct |
10 ms |
8792 KB |
Output is correct |
42 |
Correct |
11 ms |
8792 KB |
Output is correct |
43 |
Correct |
79 ms |
7760 KB |
Output is correct |
44 |
Correct |
78 ms |
7876 KB |
Output is correct |
45 |
Correct |
94 ms |
10832 KB |
Output is correct |
46 |
Correct |
92 ms |
10832 KB |
Output is correct |
47 |
Correct |
64 ms |
10684 KB |
Output is correct |
48 |
Correct |
65 ms |
10692 KB |
Output is correct |
49 |
Correct |
11 ms |
8536 KB |
Output is correct |
50 |
Correct |
10 ms |
8536 KB |
Output is correct |
51 |
Correct |
204 ms |
16320 KB |
Output is correct |
52 |
Correct |
203 ms |
16208 KB |
Output is correct |
53 |
Correct |
265 ms |
22612 KB |
Output is correct |
54 |
Correct |
261 ms |
22608 KB |
Output is correct |
55 |
Correct |
176 ms |
22352 KB |
Output is correct |
56 |
Correct |
170 ms |
22352 KB |
Output is correct |
57 |
Correct |
35 ms |
13648 KB |
Output is correct |
58 |
Correct |
36 ms |
13652 KB |
Output is correct |
59 |
Correct |
35 ms |
13832 KB |
Output is correct |
60 |
Correct |
35 ms |
13648 KB |
Output is correct |
61 |
Correct |
202 ms |
11600 KB |
Output is correct |
62 |
Correct |
207 ms |
11720 KB |
Output is correct |
63 |
Correct |
248 ms |
17744 KB |
Output is correct |
64 |
Correct |
256 ms |
17744 KB |
Output is correct |
65 |
Correct |
173 ms |
17724 KB |
Output is correct |
66 |
Correct |
176 ms |
17488 KB |
Output is correct |
67 |
Correct |
35 ms |
12624 KB |
Output is correct |
68 |
Correct |
35 ms |
12624 KB |
Output is correct |
69 |
Correct |
205 ms |
11088 KB |
Output is correct |
70 |
Correct |
220 ms |
11088 KB |
Output is correct |
71 |
Correct |
276 ms |
17236 KB |
Output is correct |
72 |
Correct |
283 ms |
17448 KB |
Output is correct |
73 |
Correct |
174 ms |
16976 KB |
Output is correct |
74 |
Correct |
180 ms |
17052 KB |
Output is correct |
75 |
Correct |
37 ms |
12624 KB |
Output is correct |
76 |
Correct |
36 ms |
12624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
6180 KB |
Output is correct |
3 |
Correct |
4 ms |
5976 KB |
Output is correct |
4 |
Correct |
3 ms |
5980 KB |
Output is correct |
5 |
Correct |
3 ms |
5976 KB |
Output is correct |
6 |
Correct |
3 ms |
5976 KB |
Output is correct |
7 |
Correct |
2 ms |
5720 KB |
Output is correct |
8 |
Correct |
2 ms |
5720 KB |
Output is correct |
9 |
Correct |
3 ms |
5720 KB |
Output is correct |
10 |
Correct |
3 ms |
5720 KB |
Output is correct |
11 |
Correct |
3 ms |
5720 KB |
Output is correct |
12 |
Correct |
3 ms |
5724 KB |
Output is correct |
13 |
Correct |
3 ms |
5720 KB |
Output is correct |
14 |
Correct |
3 ms |
5720 KB |
Output is correct |
15 |
Correct |
2 ms |
5720 KB |
Output is correct |
16 |
Correct |
2 ms |
5720 KB |
Output is correct |
17 |
Correct |
3 ms |
5720 KB |
Output is correct |
18 |
Correct |
3 ms |
5724 KB |
Output is correct |
19 |
Correct |
3 ms |
5724 KB |
Output is correct |
20 |
Correct |
3 ms |
5720 KB |
Output is correct |
21 |
Correct |
3 ms |
5720 KB |
Output is correct |
22 |
Correct |
3 ms |
5720 KB |
Output is correct |
23 |
Correct |
2 ms |
5720 KB |
Output is correct |
24 |
Correct |
2 ms |
5720 KB |
Output is correct |
25 |
Correct |
4 ms |
5976 KB |
Output is correct |
26 |
Correct |
5 ms |
5976 KB |
Output is correct |
27 |
Correct |
7 ms |
9560 KB |
Output is correct |
28 |
Correct |
7 ms |
9560 KB |
Output is correct |
29 |
Correct |
4 ms |
8280 KB |
Output is correct |
30 |
Correct |
4 ms |
8280 KB |
Output is correct |
31 |
Correct |
5 ms |
9048 KB |
Output is correct |
32 |
Correct |
5 ms |
9052 KB |
Output is correct |
33 |
Correct |
5 ms |
9048 KB |
Output is correct |
34 |
Correct |
5 ms |
9048 KB |
Output is correct |
35 |
Correct |
5 ms |
5720 KB |
Output is correct |
36 |
Correct |
4 ms |
5724 KB |
Output is correct |
37 |
Correct |
6 ms |
9560 KB |
Output is correct |
38 |
Correct |
6 ms |
9560 KB |
Output is correct |
39 |
Correct |
5 ms |
8280 KB |
Output is correct |
40 |
Correct |
5 ms |
8280 KB |
Output is correct |
41 |
Correct |
5 ms |
9180 KB |
Output is correct |
42 |
Correct |
5 ms |
9048 KB |
Output is correct |
43 |
Correct |
4 ms |
5720 KB |
Output is correct |
44 |
Correct |
4 ms |
5724 KB |
Output is correct |
45 |
Correct |
6 ms |
9304 KB |
Output is correct |
46 |
Correct |
6 ms |
9560 KB |
Output is correct |
47 |
Correct |
5 ms |
8284 KB |
Output is correct |
48 |
Correct |
4 ms |
8280 KB |
Output is correct |
49 |
Correct |
5 ms |
9048 KB |
Output is correct |
50 |
Correct |
6 ms |
9048 KB |
Output is correct |
51 |
Correct |
79 ms |
9808 KB |
Output is correct |
52 |
Correct |
80 ms |
9888 KB |
Output is correct |
53 |
Correct |
96 ms |
12880 KB |
Output is correct |
54 |
Correct |
101 ms |
12848 KB |
Output is correct |
55 |
Correct |
66 ms |
12880 KB |
Output is correct |
56 |
Correct |
67 ms |
12880 KB |
Output is correct |
57 |
Correct |
10 ms |
9048 KB |
Output is correct |
58 |
Correct |
9 ms |
9048 KB |
Output is correct |
59 |
Correct |
10 ms |
9048 KB |
Output is correct |
60 |
Correct |
10 ms |
9048 KB |
Output is correct |
61 |
Correct |
80 ms |
8020 KB |
Output is correct |
62 |
Correct |
78 ms |
7960 KB |
Output is correct |
63 |
Correct |
93 ms |
11056 KB |
Output is correct |
64 |
Correct |
93 ms |
11120 KB |
Output is correct |
65 |
Correct |
70 ms |
11088 KB |
Output is correct |
66 |
Correct |
65 ms |
10832 KB |
Output is correct |
67 |
Correct |
10 ms |
8792 KB |
Output is correct |
68 |
Correct |
11 ms |
8792 KB |
Output is correct |
69 |
Correct |
79 ms |
7760 KB |
Output is correct |
70 |
Correct |
78 ms |
7876 KB |
Output is correct |
71 |
Correct |
94 ms |
10832 KB |
Output is correct |
72 |
Correct |
92 ms |
10832 KB |
Output is correct |
73 |
Correct |
64 ms |
10684 KB |
Output is correct |
74 |
Correct |
65 ms |
10692 KB |
Output is correct |
75 |
Correct |
11 ms |
8536 KB |
Output is correct |
76 |
Correct |
10 ms |
8536 KB |
Output is correct |
77 |
Correct |
204 ms |
16320 KB |
Output is correct |
78 |
Correct |
203 ms |
16208 KB |
Output is correct |
79 |
Correct |
265 ms |
22612 KB |
Output is correct |
80 |
Correct |
261 ms |
22608 KB |
Output is correct |
81 |
Correct |
176 ms |
22352 KB |
Output is correct |
82 |
Correct |
170 ms |
22352 KB |
Output is correct |
83 |
Correct |
35 ms |
13648 KB |
Output is correct |
84 |
Correct |
36 ms |
13652 KB |
Output is correct |
85 |
Correct |
35 ms |
13832 KB |
Output is correct |
86 |
Correct |
35 ms |
13648 KB |
Output is correct |
87 |
Correct |
202 ms |
11600 KB |
Output is correct |
88 |
Correct |
207 ms |
11720 KB |
Output is correct |
89 |
Correct |
248 ms |
17744 KB |
Output is correct |
90 |
Correct |
256 ms |
17744 KB |
Output is correct |
91 |
Correct |
173 ms |
17724 KB |
Output is correct |
92 |
Correct |
176 ms |
17488 KB |
Output is correct |
93 |
Correct |
35 ms |
12624 KB |
Output is correct |
94 |
Correct |
35 ms |
12624 KB |
Output is correct |
95 |
Correct |
205 ms |
11088 KB |
Output is correct |
96 |
Correct |
220 ms |
11088 KB |
Output is correct |
97 |
Correct |
276 ms |
17236 KB |
Output is correct |
98 |
Correct |
283 ms |
17448 KB |
Output is correct |
99 |
Correct |
174 ms |
16976 KB |
Output is correct |
100 |
Correct |
180 ms |
17052 KB |
Output is correct |
101 |
Correct |
37 ms |
12624 KB |
Output is correct |
102 |
Correct |
36 ms |
12624 KB |
Output is correct |
103 |
Correct |
303 ms |
16720 KB |
Output is correct |
104 |
Correct |
298 ms |
16736 KB |
Output is correct |
105 |
Runtime error |
266 ms |
187984 KB |
Execution killed with signal 11 |
106 |
Halted |
0 ms |
0 KB |
- |