Submission #1143943

#TimeUsernameProblemLanguageResultExecution timeMemory
1143943Zero_OPPetrol stations (CEOI24_stations)C11
Compilation error
0 ms0 KiB
dit con me lai sai thuat #include <bits/stdc++.h> using namespace std; #define mp make_pair #define rep(i, l, r) for(int i = (l); i < (r); ++i) #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define sum_of(v) accumulate(all(v), 0ll) #define compact(v) v.erase(unique(all(v)), end(v)) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" #define file(task) if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using db = double; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vpi = vector<pi>; using vpl = vector<pl>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MAX = 7e4 + 5; int N, K; vpi adj[MAX]; int sz[MAX], up[MAX], par[MAX], dp[MAX]; ll result[MAX], sum[MAX]; vpi down[MAX]; bool deleted[MAX]; vector<pair<ll, int>> stck; vpi sub[MAX]; void reset_info(int u){ down[u].clear(); dp[u] = 0; } int dfs_sz(int u, int p){ reset_info(u); sz[u] = 1; for(auto [v, w] : adj[u]) if(v != p && !deleted[v]){ par[v] = u; sz[u] += dfs_sz(v, u); } return sz[u]; } int find_centroid(int u, int p, int tar){ for(auto [v, w] : adj[u]) if(v != p && !deleted[v] && sz[v] * 2 > tar){ return find_centroid(v, u, tar); } return u; } pair<int, int> search_up(ll w){ int l = 0, r = sz(stck) - 2, ans = -1, ww = -1; //(ww) : the edge to that subtree while(l <= r){ int mid = (l + r) >> 1; if(w - stck[mid].first > K) { ans = stck[mid + 1].second, ww = stck[mid + 2].first - stck[mid + 1].first, l = mid + 1; } else r = mid - 1; } return {ans, ww}; } void dfs_calc(int u, int p, ll sum_w, vpi& sub, ll cond){ if(sum_w > K) result[u] += cond; int ww; tie(up[u], ww) = search_up(sum_w); stck.push_back(mp(sum_w, u)); sum[u] = sum_w; cout << dbg(u) << dbg(up[u]) << '\n'; for(auto [v, w] : adj[u]) if(v != p && !deleted[v]) dfs_calc(v, u, sum_w + w, sub, cond); stck.pop_back(); if(up[u] != -1) { down[up[u]].emplace_back(u, ww); dp[up[u]] += dp[u] + 1; } else{ sub.emplace_back(sum[u], u); } } template<typename T> ll query(vector<T>& pref, int l, int r){ return pref[r] - (l > 0 ? pref[l - 1] : 0); } int find_upper(vpi& a, int x){ int l = 0, r = sz(a) - 1, ans = sz(a); while(l <= r){ int mid = l + r >> 1; if(a[mid].first > x) ans = mid, r = mid - 1; else l = mid + 1; } return ans; } void update_dfs(int u, ll add){ result[u] += add; for(auto [v, ww] : down[u]){ update_dfs(v, add); } } void calc(vpi& cur, int sign, vpi& val, vl& pref){ assert(sz(val) == sz(pref)); for(auto [sum_u, u] : cur){ for(auto [v, ww] : down[u]){ int L = find_upper(val, K - sum[u] - ww); int R = find_upper(val, K - sum[u]) - 1; if(L <= R){ ll s = query(pref, L, R); result[u] += s * sign; update_dfs(v, s * sign); } } } } /* centroid, u, v 1. u -> centroid -> v 2. u -> centroid 3. centroid -> v */ void decompose(int u){ u = find_centroid(u, -1, dfs_sz(u, -1)); dfs_sz(u, -1); stck = {{0, u}}; deleted[u] = 1; cout << dbg(u) << '\n'; vector<pair<int, int>> all_sub; vector<pair<int, int>> centroid_edges; for(auto [v, w] : adj[u]) if(!deleted[v]){ sub[v].clear(); dfs_calc(v, u, w, sub[v], sz[u] - sz[v]); centroid_edges.emplace_back(w, sz[v]); sort(all(sub[v])); vl pref; for(auto [sum_x, x] : sub[v]){ if(pref.empty()) pref.push_back(dp[x] + 1); else pref.emplace_back(pref.back() + dp[x] + 1); } calc(sub[v], -1, sub[v], pref); for(auto [sum_x, x] : sub[v]){ if(sum[x] + w > K){ ll ex = 1LL * sz[v] * (1 + dp[x]); result[u] -= ex; cout << dbg(x) << dbg(ex) << '\n'; } all_sub.emplace_back(sum_x, x); } } stck.clear(); //calculate contribution to result[centroid] sort(all(centroid_edges)); vl prf; for(auto [w, earn] : centroid_edges){ if(prf.empty()) prf.emplace_back(earn); else prf.emplace_back(prf.back() + earn); } for(auto [sum_x, x] : all_sub){ int L = find_upper(centroid_edges, K - sum[x]); if(L == sz(centroid_edges)) continue; ll s = query(prf, L, sz(centroid_edges) - 1); result[u] += s * (1 + dp[x]); cout << dbg(x) << dbg(s * (1 + dp[x])) << '\n'; } //calculate contribution to result[other] sort(all(all_sub)); vl pref; for(auto [sum_x, x] : all_sub){ if(pref.empty()) pref.push_back(dp[x] + 1); else pref.push_back(pref.back() + dp[x] + 1); } for(auto [v, w] : adj[u]) if(!deleted[v]){ calc(sub[v], +1, all_sub, pref); } for(auto [v, w] : adj[u]) if(!deleted[v]){ decompose(v); } } void testcase(){ cin >> N >> K; rep(i, 1, N){ int u, v, l; cin >> u >> v >> l; adj[u].push_back(mp(v, l)); adj[v].push_back(mp(u, l)); } decompose(0); rep(i, 0, N) cout << result[i] << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL int T = 1; //cin >> T; while(T--){ testcase(); } return 0; }

Compilation message (stderr)

Main.c:1:1: error: unknown type name 'dit'
    1 | dit con me lai sai thuat
      | ^~~
Main.c:1:9: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'me'
    1 | dit con me lai sai thuat
      |         ^~
Main.c:1:9: error: unknown type name 'me'
Main.c:2:10: fatal error: bits/stdc++.h: No such file or directory
    2 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.