Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void dfs_calc(int _st) {
- stack<pii> st;
- st.push(mp(_st, -1));
- while (!st.empty()) {
- int &v = st.top().first;
- int &i = st.top().second;
- if (i < 0) {
- if (v != 0) {
- pll t = m.getMin(vs[v]);
- res[v] = t.first + (dist[v] - t.second) * vs[v] + sts[v];
- }
- m.push(mp(res[v], dist[v]));
- } else {
- if (!m.history_enabled() && v == 0) {
- m = Magic();
- m.disable_history();
- m.push(mp(res[v], dist[v]));
- }
- }
- i++;
- if (i < sz(es[v])) {
- if (es[v][i] != par[v])
- st.push(mp(es[v][i], -1));
- } else {
- m.pop();
- st.pop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement