#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void setupIO(){
#define name "Whisper"
//Phu Trong from Nguyen Tat Thanh High School for gifted student
srand(time(NULL));
cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
cout << fixed << setprecision(10);
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
int numNode, nLicense;
const int MAX = 1e5 + 5;
struct Edge{
int u, v, l, r;
Edge(){}
Edge(int _u, int _v, int _l, int _r){
u = _u;
v = _v;
l = _l;
r = _r;
}
int other(int x){
return (u ^ v ^ x);
}
} edge[MAX];
vector<int> G[MAX];
int ans[MAX];
struct Node{
int l, r, cnt, cover;
Node(): l(-1), r(-1), cnt(0), cover(0){}
Node(int _l, int _r, int _cnt, int _cover): l(_l), r(_r), cnt(_cnt), cover(_cover){}
};
struct SparseSegmentTree{
vector<Node> st;
int n;
SparseSegmentTree(): st(MAX * 60), n(1){}
void modify(int u, int v, int val, int id = 1, int l = 1, int r = 2e9){
if (u > r || v < l) return;
if (u <= l && v >= r) {
st[id].cover += val;
if (st[id].cover != 0) st[id].cnt = r - l + 1;
else if(l != r) st[id].cnt = st[id << 1].cnt + st[id << 1 | 1].cnt;
else st[id].cnt = 0;
return;
}
if (st[id].l == -1) st[id].l = ++n;
if (st[id].r == -1) st[id].r = ++n;
int mid = (l + r) >> 1;
modify(u, v, val, st[id].l, l, mid);
modify(u, v, val, st[id].r, mid + 1, r);
if (st[id].cover != 0) st[id].cnt = r - l + 1;
else st[id].cnt = st[st[id].l].cnt + st[st[id].r].cnt;
}
int query(int u, int v, int id = 1, int l = 1, int r = 2e9){
if (u > r || v < l) return 0;
if (u <= l && v >= r) return st[id].cnt;
int mid = (l + r) >> 1;
if (st[id].l == -1) st[id].l = ++n;
if (st[id].r == -1) st[id].r = ++n;
int ql = query(u, v, st[id].l, l, mid);
int qr = query(u, v, st[id].r, mid + 1, r);
return (ql + qr);
}
} st;
void dfs(int u, int p = -1){
ans[u] = st.st[1].cnt;
for (int&i : G[u]) {
int v = edge[i].other(u);
int l = edge[i].l, r = edge[i].r;
if(v ^ p){
st.modify(l, r, 1);
dfs(v, u);
st.modify(l, r, -1);
}
}
}
void Whisper(){
cin >> numNode >> nLicense;
for (int i = 1; i < numNode; ++i){
cin >> edge[i].u >> edge[i].v >> edge[i].l >> edge[i].r;
G[edge[i].u].emplace_back(i);
G[edge[i].v].emplace_back(i);
}
dfs(1);
for (int i = 2; i <= numNode; ++i) cout << ans[i] << '\n';
}
signed main(){
setupIO();
int Test = 1;
// cin >> Test;
for ( int i = 1 ; i <= Test ; i++ ){
Whisper();
if (i < Test) cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
192532 KB |
Output is correct |
2 |
Correct |
31 ms |
192452 KB |
Output is correct |
3 |
Correct |
30 ms |
192500 KB |
Output is correct |
4 |
Correct |
30 ms |
192300 KB |
Output is correct |
5 |
Correct |
29 ms |
192348 KB |
Output is correct |
6 |
Correct |
30 ms |
192336 KB |
Output is correct |
7 |
Correct |
29 ms |
192388 KB |
Output is correct |
8 |
Correct |
28 ms |
192336 KB |
Output is correct |
9 |
Incorrect |
31 ms |
192460 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
192532 KB |
Output is correct |
2 |
Correct |
31 ms |
192452 KB |
Output is correct |
3 |
Correct |
30 ms |
192500 KB |
Output is correct |
4 |
Correct |
30 ms |
192300 KB |
Output is correct |
5 |
Correct |
29 ms |
192348 KB |
Output is correct |
6 |
Correct |
30 ms |
192336 KB |
Output is correct |
7 |
Correct |
29 ms |
192388 KB |
Output is correct |
8 |
Correct |
28 ms |
192336 KB |
Output is correct |
9 |
Incorrect |
31 ms |
192460 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
192532 KB |
Output is correct |
2 |
Correct |
31 ms |
192452 KB |
Output is correct |
3 |
Correct |
30 ms |
192500 KB |
Output is correct |
4 |
Correct |
30 ms |
192300 KB |
Output is correct |
5 |
Correct |
29 ms |
192348 KB |
Output is correct |
6 |
Correct |
30 ms |
192336 KB |
Output is correct |
7 |
Correct |
29 ms |
192388 KB |
Output is correct |
8 |
Correct |
28 ms |
192336 KB |
Output is correct |
9 |
Incorrect |
31 ms |
192460 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
192532 KB |
Output is correct |
2 |
Correct |
31 ms |
192452 KB |
Output is correct |
3 |
Correct |
30 ms |
192500 KB |
Output is correct |
4 |
Correct |
30 ms |
192300 KB |
Output is correct |
5 |
Correct |
29 ms |
192348 KB |
Output is correct |
6 |
Correct |
30 ms |
192336 KB |
Output is correct |
7 |
Correct |
29 ms |
192388 KB |
Output is correct |
8 |
Correct |
28 ms |
192336 KB |
Output is correct |
9 |
Incorrect |
31 ms |
192460 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
192532 KB |
Output is correct |
2 |
Correct |
31 ms |
192452 KB |
Output is correct |
3 |
Correct |
30 ms |
192500 KB |
Output is correct |
4 |
Correct |
30 ms |
192300 KB |
Output is correct |
5 |
Correct |
29 ms |
192348 KB |
Output is correct |
6 |
Correct |
30 ms |
192336 KB |
Output is correct |
7 |
Correct |
29 ms |
192388 KB |
Output is correct |
8 |
Correct |
28 ms |
192336 KB |
Output is correct |
9 |
Incorrect |
31 ms |
192460 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |