Advertisement
Guest User

Untitled

a guest
Jul 4th, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. void dfs_calc(int _st) {
  2.   stack<pii> st;
  3.  
  4.   st.push(mp(_st, -1));
  5.   while (!st.empty()) {
  6.     int &v = st.top().first;
  7.     int &i = st.top().second;
  8.     if (i < 0) {
  9.       if (v != 0) {
  10.         pll t = m.getMin(vs[v]);
  11.         res[v] = t.first + (dist[v] - t.second) * vs[v] + sts[v];
  12.       }
  13.       m.push(mp(res[v], dist[v]));
  14.     } else {
  15.       if (!m.history_enabled() && v == 0) {
  16.         m = Magic();
  17.         m.disable_history();
  18.         m.push(mp(res[v], dist[v]));
  19.       }      
  20.     }
  21.     i++;
  22.     if (i < sz(es[v])) {
  23.       if (es[v][i] != par[v])
  24.         st.push(mp(es[v][i], -1));
  25.     } else {
  26.       m.pop();
  27.       st.pop();
  28.     }
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement