func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   vector<pair<long long, long long> > g[N];   int n, m;   stack<int> st;   bool inStack[N];   int cmp[N], ind[N], low[N], cnt, cont;   void dfs(int x) {     ind[x] = low[x] = cnt++;     st.push(x);     inStack[x] = true;     for (int i = 0; i < g[x].size(); ++i) {       int y = g[x][i].first;       if (ind[y] == -1) {         dfs(y);         low[x] = min(low[x], low[y]);       } else if (inStack[y]) {         low[x] = min(low[x], ind[y]);       }     }     if (ind[x] == low[x]) {       int idx;       do {         idx = st.top();         st.pop();         inStack[idx] = 0;         cmp[idx] = cont;       } while (idx != x);       cont++;     }   }   inline void initTarjan() { memset(ind, -1, sizeof ind); }   bool componentProcessed[N];   vector<pair<long long, long long> > compressedGraph[N];   long long componentCost[N];   inline long long getCost(long long x) {     long long lo = 0, hi = 1000000LL;     while (lo < hi) {       long long md = (lo + hi + 1) >> 1;       if ((md * (md - 1)) / 2LL <= x)         lo = md;       else         hi = md - 1;     }     return x * lo - lo * (lo + 1) * (lo - 1) / 6LL;   }   long long pd[N];   long long func(int x) {     if (pd[x] != -1) return pd[x];     pd[x] = componentCost[x];     for (int i = 0; i < compressedGraph[x].size(); ++i) {       int y = compressedGraph[x][i].first;       long long w = compressedGraph[x][i].second;       pd[x] = max(pd[x], func(y) + w + componentCost[x]);     }     return pd[x];   }   int main() {     initTarjan();     scanf( %d %d , &n, &m);     for (int i = 0; i < m; ++i) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       g[a].emplace_back(make_pair(b, c));     }     for (int i = 1; i <= n; ++i) {       if (ind[i] == -1) dfs(i);     }     int s;     scanf( %d , &s);     for (int x = 1; x <= n; ++x) {       for (int j = 0; j < g[x].size(); ++j) {         int y = g[x][j].first;         if (cmp[x] != cmp[y])           compressedGraph[cmp[x]].emplace_back(make_pair(cmp[y], g[x][j].second));         else           componentCost[cmp[x]] += getCost(g[x][j].second);       }     }     memset(pd, -1, sizeof pd);     printf( %lld n , func(cmp[s]));     return 0;   }   