#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];
vector<int> b;
int ans[MX];
void compress(vector<int> &v){
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
int lb(int val, vector<int> &v){
return lower_bound(v.begin(), v.end(), val) - v.begin() + 1;
}
struct node{
int good, sum;
node(){
good = sum = 0;
}
};
struct SMT{
vector<node> tree;
int n = 1e6 + 5;
SMT(){
tree.assign(4*n + 5, node());
};
void update(int id, int l, int r, int u, int v, int val, int len){
if(r < u || l > v){
return;
}
if(u <= l && r <= v){
tree[id].good += val;
tree[id].sum = (tree[id].good ? len : 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, len);
update(ID|1, mid+1, r, u, v, val, len);
tree[id].sum = (tree[id].good ? len : tree[ID].sum + tree[ID|1].sum);
}
void update(int l, int r, int val){
int len = r-l+1;
int u = lb(l, b);
int v = lb(r, b);
update(1, 1, n, u, v, val, len);
}
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, len;
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}});
b.push_back(l);
b.push_back(r);
}
compress(b);
dfs(1, 0);
for(int i=2; i<=n; ++i){
cout<<ans[i]<<endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:75:22: warning: unused variable 'len' [-Wunused-variable]
75 | int v, l, r, len;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
66288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
66288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
66288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
66288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
66288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |