This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
void dfs(int u, int p){
ans[u] = (R[u] - L[u] + 1);
for(pair<int, pii> e : gr[u]){
int v, l, r;
v = e.first;
tie(l, r) = e.second;
if(v != p){
L[v] = min({L[v], L[u], l});
R[v] = max({R[v], R[u], r});
dfs(v, u);
}
}
}
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}});
}
memset(L, 63, sizeof L);
memset(R, -63, sizeof R);
dfs(1, 0);
for(int i=2; i<=n; ++i){
cout<<ans[i]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |