#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pii pair<int, int>
const int MX = 1e5 + 5;
vector<pair<int, pii>> gr[MX];
int L[MX], R[MX], f[MX];
int ans[MX];
struct node{
int good, sum;
node(){
good = sum = 0;
}
};
struct SMT{
vector<node> tree;
int n = 2e5 + 5;
SMT(){
tree.assign(4*n + 5, node());
};
void update(int id, int l, int r, int u, int v, int val){
if(r < u || l > v){
return;
}
if(u <= l && r <= v){
tree[id].good += val;
tree[id].sum = (tree[id].good ? r-l+1 : tree[2*id].sum + tree[2*id+1].sum);
return;
}
int mid = (l + r) >> 1, ID = (id << 1);
update(ID, l, mid, u, v, val);
update(ID|1, mid+1, r, u, v, val);
tree[id].sum = (tree[id].good ? r-l+1 : tree[ID].sum + tree[ID|1].sum);
}
void update(int l, int r, int val){
update(1, 1, n, l, r, val);
}
int get(int id, int l, int r, int u, int v){
if(r < u || l > v){
return 0;
}
if(u <= l && r <= v){
return tree[id].sum;
}
int mid = (l + r) >> 1, ID = (id << 1);
return get(ID, l, mid, u, v) + get(ID|1, mid+1, r, u, v);
}
};
SMT smt;
void dfs(int u, int p){
ans[u] = smt.tree[1].sum;
for(pair<int, pii> e : gr[u]){
int v, l, r;
v = e.first;
tie(l, r) = e.second;
if(v != p){
smt.update(l, r, 1);
dfs(v, u);
smt.update(l, r, -1);
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("main.inp","r",stdin);
//freopen("main.out","w",stdout);
int n, m;
cin>>n>>m;
for(int i=1; i<n; ++i){
int u, v, l, r;
cin>>u>>v>>l>>r;
gr[u].push_back({v, {l, r}});
gr[v].push_back({u, {l, r}});
}
dfs(1, 0);
for(int i=2; i<=n; ++i){
cout<<ans[i]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16476 KB |
Output is correct |
2 |
Correct |
5 ms |
16472 KB |
Output is correct |
3 |
Correct |
6 ms |
16628 KB |
Output is correct |
4 |
Correct |
5 ms |
16472 KB |
Output is correct |
5 |
Correct |
6 ms |
16476 KB |
Output is correct |
6 |
Correct |
4 ms |
16472 KB |
Output is correct |
7 |
Correct |
4 ms |
16220 KB |
Output is correct |
8 |
Correct |
4 ms |
16220 KB |
Output is correct |
9 |
Correct |
6 ms |
16220 KB |
Output is correct |
10 |
Correct |
5 ms |
16260 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16264 KB |
Output is correct |
13 |
Correct |
5 ms |
16220 KB |
Output is correct |
14 |
Correct |
5 ms |
16204 KB |
Output is correct |
15 |
Correct |
4 ms |
16220 KB |
Output is correct |
16 |
Correct |
3 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16216 KB |
Output is correct |
19 |
Correct |
5 ms |
16220 KB |
Output is correct |
20 |
Correct |
5 ms |
16248 KB |
Output is correct |
21 |
Correct |
5 ms |
16220 KB |
Output is correct |
22 |
Correct |
5 ms |
16220 KB |
Output is correct |
23 |
Correct |
6 ms |
16216 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16476 KB |
Output is correct |
2 |
Correct |
5 ms |
16472 KB |
Output is correct |
3 |
Correct |
6 ms |
16628 KB |
Output is correct |
4 |
Correct |
5 ms |
16472 KB |
Output is correct |
5 |
Correct |
6 ms |
16476 KB |
Output is correct |
6 |
Correct |
4 ms |
16472 KB |
Output is correct |
7 |
Correct |
4 ms |
16220 KB |
Output is correct |
8 |
Correct |
4 ms |
16220 KB |
Output is correct |
9 |
Correct |
6 ms |
16220 KB |
Output is correct |
10 |
Correct |
5 ms |
16260 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16264 KB |
Output is correct |
13 |
Correct |
5 ms |
16220 KB |
Output is correct |
14 |
Correct |
5 ms |
16204 KB |
Output is correct |
15 |
Correct |
4 ms |
16220 KB |
Output is correct |
16 |
Correct |
3 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16216 KB |
Output is correct |
19 |
Correct |
5 ms |
16220 KB |
Output is correct |
20 |
Correct |
5 ms |
16248 KB |
Output is correct |
21 |
Correct |
5 ms |
16220 KB |
Output is correct |
22 |
Correct |
5 ms |
16220 KB |
Output is correct |
23 |
Correct |
6 ms |
16216 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
25 |
Incorrect |
4 ms |
16476 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16476 KB |
Output is correct |
2 |
Correct |
5 ms |
16472 KB |
Output is correct |
3 |
Correct |
6 ms |
16628 KB |
Output is correct |
4 |
Correct |
5 ms |
16472 KB |
Output is correct |
5 |
Correct |
6 ms |
16476 KB |
Output is correct |
6 |
Correct |
4 ms |
16472 KB |
Output is correct |
7 |
Correct |
4 ms |
16220 KB |
Output is correct |
8 |
Correct |
4 ms |
16220 KB |
Output is correct |
9 |
Correct |
6 ms |
16220 KB |
Output is correct |
10 |
Correct |
5 ms |
16260 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16264 KB |
Output is correct |
13 |
Correct |
5 ms |
16220 KB |
Output is correct |
14 |
Correct |
5 ms |
16204 KB |
Output is correct |
15 |
Correct |
4 ms |
16220 KB |
Output is correct |
16 |
Correct |
3 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16216 KB |
Output is correct |
19 |
Correct |
5 ms |
16220 KB |
Output is correct |
20 |
Correct |
5 ms |
16248 KB |
Output is correct |
21 |
Correct |
5 ms |
16220 KB |
Output is correct |
22 |
Correct |
5 ms |
16220 KB |
Output is correct |
23 |
Correct |
6 ms |
16216 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
25 |
Correct |
37 ms |
27276 KB |
Output is correct |
26 |
Correct |
38 ms |
27348 KB |
Output is correct |
27 |
Correct |
47 ms |
27228 KB |
Output is correct |
28 |
Correct |
51 ms |
27240 KB |
Output is correct |
29 |
Correct |
35 ms |
27220 KB |
Output is correct |
30 |
Correct |
36 ms |
27440 KB |
Output is correct |
31 |
Correct |
7 ms |
17296 KB |
Output is correct |
32 |
Correct |
8 ms |
17244 KB |
Output is correct |
33 |
Correct |
7 ms |
17240 KB |
Output is correct |
34 |
Correct |
7 ms |
17244 KB |
Output is correct |
35 |
Correct |
38 ms |
22356 KB |
Output is correct |
36 |
Correct |
49 ms |
22500 KB |
Output is correct |
37 |
Correct |
48 ms |
22352 KB |
Output is correct |
38 |
Correct |
51 ms |
22608 KB |
Output is correct |
39 |
Correct |
35 ms |
22352 KB |
Output is correct |
40 |
Correct |
36 ms |
22352 KB |
Output is correct |
41 |
Correct |
8 ms |
16728 KB |
Output is correct |
42 |
Correct |
9 ms |
16732 KB |
Output is correct |
43 |
Correct |
43 ms |
21608 KB |
Output is correct |
44 |
Correct |
39 ms |
21848 KB |
Output is correct |
45 |
Correct |
52 ms |
21848 KB |
Output is correct |
46 |
Correct |
51 ms |
21844 KB |
Output is correct |
47 |
Correct |
48 ms |
21756 KB |
Output is correct |
48 |
Correct |
34 ms |
21584 KB |
Output is correct |
49 |
Correct |
7 ms |
16984 KB |
Output is correct |
50 |
Correct |
8 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16476 KB |
Output is correct |
2 |
Correct |
5 ms |
16472 KB |
Output is correct |
3 |
Correct |
6 ms |
16628 KB |
Output is correct |
4 |
Correct |
5 ms |
16472 KB |
Output is correct |
5 |
Correct |
6 ms |
16476 KB |
Output is correct |
6 |
Correct |
4 ms |
16472 KB |
Output is correct |
7 |
Correct |
4 ms |
16220 KB |
Output is correct |
8 |
Correct |
4 ms |
16220 KB |
Output is correct |
9 |
Correct |
6 ms |
16220 KB |
Output is correct |
10 |
Correct |
5 ms |
16260 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16264 KB |
Output is correct |
13 |
Correct |
5 ms |
16220 KB |
Output is correct |
14 |
Correct |
5 ms |
16204 KB |
Output is correct |
15 |
Correct |
4 ms |
16220 KB |
Output is correct |
16 |
Correct |
3 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16216 KB |
Output is correct |
19 |
Correct |
5 ms |
16220 KB |
Output is correct |
20 |
Correct |
5 ms |
16248 KB |
Output is correct |
21 |
Correct |
5 ms |
16220 KB |
Output is correct |
22 |
Correct |
5 ms |
16220 KB |
Output is correct |
23 |
Correct |
6 ms |
16216 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
25 |
Correct |
37 ms |
27276 KB |
Output is correct |
26 |
Correct |
38 ms |
27348 KB |
Output is correct |
27 |
Correct |
47 ms |
27228 KB |
Output is correct |
28 |
Correct |
51 ms |
27240 KB |
Output is correct |
29 |
Correct |
35 ms |
27220 KB |
Output is correct |
30 |
Correct |
36 ms |
27440 KB |
Output is correct |
31 |
Correct |
7 ms |
17296 KB |
Output is correct |
32 |
Correct |
8 ms |
17244 KB |
Output is correct |
33 |
Correct |
7 ms |
17240 KB |
Output is correct |
34 |
Correct |
7 ms |
17244 KB |
Output is correct |
35 |
Correct |
38 ms |
22356 KB |
Output is correct |
36 |
Correct |
49 ms |
22500 KB |
Output is correct |
37 |
Correct |
48 ms |
22352 KB |
Output is correct |
38 |
Correct |
51 ms |
22608 KB |
Output is correct |
39 |
Correct |
35 ms |
22352 KB |
Output is correct |
40 |
Correct |
36 ms |
22352 KB |
Output is correct |
41 |
Correct |
8 ms |
16728 KB |
Output is correct |
42 |
Correct |
9 ms |
16732 KB |
Output is correct |
43 |
Correct |
43 ms |
21608 KB |
Output is correct |
44 |
Correct |
39 ms |
21848 KB |
Output is correct |
45 |
Correct |
52 ms |
21848 KB |
Output is correct |
46 |
Correct |
51 ms |
21844 KB |
Output is correct |
47 |
Correct |
48 ms |
21756 KB |
Output is correct |
48 |
Correct |
34 ms |
21584 KB |
Output is correct |
49 |
Correct |
7 ms |
16984 KB |
Output is correct |
50 |
Correct |
8 ms |
16728 KB |
Output is correct |
51 |
Correct |
89 ms |
40592 KB |
Output is correct |
52 |
Correct |
97 ms |
41044 KB |
Output is correct |
53 |
Correct |
122 ms |
41100 KB |
Output is correct |
54 |
Correct |
115 ms |
41252 KB |
Output is correct |
55 |
Correct |
89 ms |
40788 KB |
Output is correct |
56 |
Correct |
93 ms |
40840 KB |
Output is correct |
57 |
Correct |
18 ms |
20824 KB |
Output is correct |
58 |
Correct |
18 ms |
20816 KB |
Output is correct |
59 |
Correct |
18 ms |
20828 KB |
Output is correct |
60 |
Correct |
18 ms |
20828 KB |
Output is correct |
61 |
Correct |
116 ms |
28412 KB |
Output is correct |
62 |
Correct |
117 ms |
28928 KB |
Output is correct |
63 |
Correct |
133 ms |
28672 KB |
Output is correct |
64 |
Correct |
147 ms |
28792 KB |
Output is correct |
65 |
Correct |
94 ms |
28900 KB |
Output is correct |
66 |
Correct |
90 ms |
28496 KB |
Output is correct |
67 |
Correct |
19 ms |
18268 KB |
Output is correct |
68 |
Correct |
18 ms |
18268 KB |
Output is correct |
69 |
Correct |
111 ms |
26784 KB |
Output is correct |
70 |
Correct |
95 ms |
26768 KB |
Output is correct |
71 |
Correct |
136 ms |
27220 KB |
Output is correct |
72 |
Correct |
130 ms |
27220 KB |
Output is correct |
73 |
Correct |
123 ms |
26708 KB |
Output is correct |
74 |
Correct |
93 ms |
26776 KB |
Output is correct |
75 |
Correct |
21 ms |
18000 KB |
Output is correct |
76 |
Correct |
20 ms |
18156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16476 KB |
Output is correct |
2 |
Correct |
5 ms |
16472 KB |
Output is correct |
3 |
Correct |
6 ms |
16628 KB |
Output is correct |
4 |
Correct |
5 ms |
16472 KB |
Output is correct |
5 |
Correct |
6 ms |
16476 KB |
Output is correct |
6 |
Correct |
4 ms |
16472 KB |
Output is correct |
7 |
Correct |
4 ms |
16220 KB |
Output is correct |
8 |
Correct |
4 ms |
16220 KB |
Output is correct |
9 |
Correct |
6 ms |
16220 KB |
Output is correct |
10 |
Correct |
5 ms |
16260 KB |
Output is correct |
11 |
Correct |
5 ms |
16220 KB |
Output is correct |
12 |
Correct |
5 ms |
16264 KB |
Output is correct |
13 |
Correct |
5 ms |
16220 KB |
Output is correct |
14 |
Correct |
5 ms |
16204 KB |
Output is correct |
15 |
Correct |
4 ms |
16220 KB |
Output is correct |
16 |
Correct |
3 ms |
16220 KB |
Output is correct |
17 |
Correct |
5 ms |
16220 KB |
Output is correct |
18 |
Correct |
5 ms |
16216 KB |
Output is correct |
19 |
Correct |
5 ms |
16220 KB |
Output is correct |
20 |
Correct |
5 ms |
16248 KB |
Output is correct |
21 |
Correct |
5 ms |
16220 KB |
Output is correct |
22 |
Correct |
5 ms |
16220 KB |
Output is correct |
23 |
Correct |
6 ms |
16216 KB |
Output is correct |
24 |
Correct |
5 ms |
16220 KB |
Output is correct |
25 |
Incorrect |
4 ms |
16476 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |