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;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
const int MXN = 200005;
int n, m, eu[MXN], ev[MXN], el[MXN], er[MXN], ans[MXN];
int N;
vector<int> eid[MXN];
vector<pii> dist;
struct SMG {
#define mid ((l + r) >> 1)
int b[MXN * 4], c[MXN * 4];
void UPD(int id, int l, int r) {
if (b[id]) c[id] = dist[r].fs - dist[l].fs;
else {
c[id] = 0;
if (l + 1 < r) c[id] = c[id * 2 + 1] + c[id * 2 + 2];
}
}
void ADD(int id, int l, int r, int _l, int _r) {
if (_l <= l && r <= _r) {
b[id]++;
UPD(id, l, r);
return;
}
if (_l < mid) ADD(id * 2 + 1, l, mid, _l, _r);
if (mid < _r) ADD(id * 2 + 2, mid, r, _l, _r);
UPD(id, l, r);
}
void REM(int id, int l, int r, int _l, int _r) {
if (_l <= l && r <= _r) {
b[id]--;
UPD(id, l, r);
return;
}
if (_l < mid) REM(id * 2 + 1, l, mid, _l, _r);
if (mid < _r) REM(id * 2 + 2, mid, r, _l, _r);
UPD(id, l, r);
}
} smg;
void DIST() {
FOR(i, 1, n) {
dist.push_back(mp(el[i], i));
dist.push_back(mp(er[i], i + n));
}
sort(dist.begin(), dist.end());
FOR(i, 0, dist.size()) {
auto [_, id] = dist[i];
if (id < n) el[id] = i;
else er[id - n] = i;
}
}
void DFS(int id, int par) {
ans[id] = smg.c[0];
for (auto &e : eid[id]) {
int i = eu[e] ^ ev[e] ^ id;
if (i == par) continue;
debug(el[e], er[e], '+');
smg.ADD(0, 0, N, el[e], er[e]);
DFS(i, id);
debug(el[e], er[e], '-');
smg.REM(0, 0, N, el[e], er[e]);
}
}
void miku() {
cin >> n >> m;
N = 2 * n - 2;
FOR(i, 1, n) {
cin >> eu[i] >> ev[i] >> el[i] >> er[i];
er[i]++;
eid[eu[i]].push_back(i);
eid[ev[i]].push_back(i);
}
DIST();
DFS(1, 0);
FOR(i, 2, n + 1) cout << ans[i] << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void DFS(int, int)':
Main.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
Main.cpp:77:9: note: in expansion of macro 'debug'
77 | debug(el[e], er[e], '+');
| ^~~~~
Main.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
Main.cpp:80:9: note: in expansion of macro 'debug'
80 | debug(el[e], er[e], '-');
| ^~~~~
# | 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... |