Submission #610225

# Submission time Handle Problem Language Result Execution time Memory
610225 2022-07-28T05:53:34 Z RandomLB Harbingers (CEOI09_harbingers) C++17
50 / 100
120 ms 25268 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
template<class T> using indexed_set = tree<T, null_type, less_equal<T>,
        rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order //(k-indexed val with 0-indexing)
#define ook order_of_key //(num of vals in set that are strictly less)
#define ms(x, a) memset(x, a, sizeof(x))
#define siz(x) (int)x.size()
#define len(x) (int)x.length()
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define fin(x) cout << x; return
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vals, Args&&... values){
    cout << vals << " = ";
    string delim = "";
    (...,(cout << delim << values, delim = ", "));
    cout << endl;
}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
//===========================================
const int MAX = 1e5+5;
vector<pi> adj[MAX];
ll cost[MAX], speed[MAX], dep[MAX], dp[MAX];
deque<int> q;
 
inline ld sect(int x, int y){
    return (ld)(dp[y]-dp[x])/(-dep[x]+dep[y]);
}
 
void dfs(int v, int p){
    if (v > 1){
        int l = -1, r = siz(q)-1;
        while (l+1 < r){
            int m = l+(r-l)/2;
            if (sect(q[m], q[m+1]) >= speed[v]) r = m;
            else l = m;
        }
        int u = q[r];
        dp[v] = cost[v]+speed[v]*(dep[v]-dep[u])+dp[u];
        //deb(v, u, dp[v]);
        while (siz(q) > 1 && sect(q.back(), q[siz(q)-2]) >= sect(q.back(), v)) q.pop_back();
    }
    q.push_back(v);
    for (auto[u, w]: adj[v]){
        if (u == p) continue;
        dep[u] = dep[v]+w;
        dfs(u, v);
    }
    if (q.back() == v) q.pop_back();
}
 
int main(){
    cin.tie(0)->sync_with_stdio(0);
    //freopen("test.txt", "r", stdin);
    int n; cin >> n;
    for (int i = 1; i < n; i++){
        int a, b, w;
        cin >> a >> b >> w;
        adj[a].pb({b, w});
        adj[b].pb({a, w});
    }
    for (int i = 2; i <= n; i++) cin >> cost[i] >> speed[i];
    dfs(1, -1);
    for (int i = 2; i <= n; i++) cout << dp[i] << (i==n?"\n":" ");
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Correct 4 ms 3156 KB Output is correct
3 Correct 51 ms 11980 KB Output is correct
4 Correct 68 ms 16588 KB Output is correct
5 Correct 70 ms 20920 KB Output is correct
6 Correct 120 ms 25268 KB Output is correct
7 Incorrect 52 ms 11980 KB Output isn't correct
8 Incorrect 96 ms 16864 KB Output isn't correct
9 Incorrect 102 ms 19716 KB Output isn't correct
10 Incorrect 78 ms 18404 KB Output isn't correct