This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"
using namespace std;
int n, m;
vector<int> cnt, ans;
vector<vector<tuple<int, int, int>>> g;
void dfs(int u, int p, int l, int r) {
for (int i = l; i <= r; i++) cnt[i]++;
for (int i = 1; i <= m; i++) ans[u] += cnt[i] > 0;
for (auto [v, lx, rx]: g[u]) {
if (v != p) {
dfs(v, u, lx, rx);
}
}
for (int i = l; i <= r; i++) cnt[i]--;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
g.assign(n + 1, {});
ans.assign(n + 1, 0);
cnt.assign(m + 1, 0);
for (int i = 1; i < n; i++) {
int u, v, l, r;
cin >> u >> v >> l >> r;
g[u].emplace_back(v, l, r);
g[v].emplace_back(u, l, r);
}
dfs(1, 0, 1, 0);
for (int i = 2; i <= n; i++) cout << ans[i] << '\n';
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... |