This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int inf = 1e9 + 7;
void solve(){
int n,m;
cin >> n >> m;
vector < vector < int > > tree[n];
for(int i = 1;i<n;i++){
int a,b,c,d;
cin >> a >> b >> c >> d;
a-- , b--;
tree[a].push_back({b,c,d});
tree[b].push_back({a,c,d});
}
pair < int , int > pai[n];
function<void(int,int)> dfs = [&](int node , int par){
for(auto itr : tree[node]){
if(itr[0] == par)continue;
pai[itr[0]] = {min(pai[node].first , itr[1]) , max(pai[node].second , itr[2])};
dfs(itr[0] , node);
}
};
pai[0] = {inf , -inf};
dfs(0 , 0);
for(int i = 1;i<n;i++){
cout << pai[i].second - pai[i].first + 1 << '\n';
}
cout << endl;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
# | 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... |