Submission #1063757

#TimeUsernameProblemLanguageResultExecution timeMemory
1063757trMatherzHarbingers (CEOI09_harbingers)C++17
0 / 100
129 ms65536 KiB
#include <iostream> // #include <fstream> // std::ifstream cin ("pushabox.in"); // std::ofstream cout ("pushabox.out"); // includes #include <cmath> #include <set> #include <map> #include <queue> #include <string> #include <vector> #include <array> #include <algorithm> #include <numeric> #include <iomanip> #include <unordered_set> #include <stack> #include <ext/pb_ds/assoc_container.hpp> #include <random> #include <chrono> #include <bitset> #include <complex> // usings using namespace std; using namespace __gnu_pbds; // misc #define ll long long #define ld long double #define pb push_back #define pq priority_queue #define ub upper_bound #define lb lower_bound template <typename T, typename U> bool emin(T &a, const U &b) { return b < a ? a = b, true : false; } template <typename T, typename U> bool emax(T &a, const U &b) { return b > a ? a = b, true : false; } typedef uint64_t hash_t; // vectors #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vpii vector<pair<int, int>> #define vvpii vector<vector<pair<int, int>>> #define vppipi vector<pair<int, pair<int, int>>> #define vl vector<ll> #define vvl vector<vl> #define vvvl vector<vvl> #define vpll vector<pair<ll, ll>> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define vvvb vector<vvb> #define vs vector<string> #define sz(x) (int)x.size() #define rz resize #define all(x) x.begin(), x.end() #define vc vector<char> #define vvc vector<vc> // pairs #define pii pair<int, int> #define pll pair<ll, ll> #define mp make_pair #define f first #define s second // sets #define si set<int> #define sl set<ll> #define ss set<string> #define in insert template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // maps #define mii map<int, int> #define mll map<ll, ll> // loops #define FR(x, z, y) for (int x = z; x < y; x++) #define FRE(x, z, y) FR(x, z, y + 1) #define F(x, y) FR(x, 0, y) #define FE(x, y) F(x, y + 1) #define A(x, y) for (auto &x : y) ld isect(pll a, pll b) { return (ld) (a.s - b.s) / (b.f - a.f); } int n; vl d, dp; vvpll a; vpll b, c; int pos = 0; int sz = 1; int add(ll k, ll m){ for(int i = sz; i > 1; i--) { if(isect(c[i - 1], c[i]) < isect(c[i - 1], {k, m})) return i; } return 1; } ll get(ll x){ ll ret = 0; for(int i = 0; i < sz; i++){ emin(ret, c[i].f * x + c[i].s); } return ret; } void dfs(int x, int p){ int pos, prev = sz; pll past; auto y = c; if(p != -1) { dp[x] = b[x].f + b[x].s * d[x] + min(get(b[x].s), 0ll); pos = add(-d[x], dp[x]); past = c[pos]; c[pos] = { -d[x], dp[x] }; sz = pos + 1; } A(u, a[x]) { if(u.f == p) continue; d[u.f] = d[x] + u.s; dfs(u.f, x); } if(p != -1) { sz = prev; c[pos] = past; c = y; } } int main() { cin >> n; a = vvpll(n); b = c = vpll(n, {(ll) 1e9, (ll) 1e9}); c[0] = {0, 0}; d = dp = vl(n, 0); F(i, n - 1){ ll x, y, z; cin >> x >> y >> z; x--; y--; a[x].pb({y, z}); a[y].pb({x, z}); } F(i, n - 1) cin >> b[i + 1].f >> b[i + 1].s; dfs(0, -1); F(i, n - 1) cout << dp[i + 1] << " "; }

Compilation message (stderr)

harbingers.cpp: In function 'void dfs(int, int)':
harbingers.cpp:125:14: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
  125 |         c[pos] = past;
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...