func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T0, typename T1>   bool chkmin(T0 &a, const T1 &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T0, typename T1>   bool chkmax(T0 &a, const T1 &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f, Max_val = 314000000;   const int maxn = 100000, maxm = 100000;   int deg[maxn + 5];   pair<pair<int, int>, int> all[maxm + 5];   int tmp[maxm + 5] = {0};   vector<int> yyt[maxn + 5];   bool vis[maxn + 5] = {0};   int Min[maxn + 5];   int Max[maxn + 5];   vector<int> zzj[maxm + 5];   vector<int> owaski[maxn + 5];   int find(const int &first) {     if (vis[first]) return -2;     if (Max[first]) return Max[first];     vis[first] = 1;     Max[first] = -2;     for (int i = (0), _end_ = ((int((owaski[first]).size()))); i != _end_; ++i) {       const int &second = owaski[first][i];       int tmp = ::tmp[second];       for (int j = (0), _end_ = ((int((zzj[second]).size()))); j != _end_; ++j) {         const int &k = zzj[second][j];         int tmp0 = find(k);         if (tmp0 == -1)           goto yyt;         else if (tmp0 == -2)           tmp = -2;         else if (tmp != -2)           chkmin(tmp += tmp0, Max_val);       }       if (tmp == -2) {         Max[first] = -2;         vis[first] = 0;         return Max[first];       }       Max[first] = max(Max[first], tmp);     yyt:;     }     vis[first] = 0;     return Max[first];   }   int m, n;   int main() {     memset(Min, oo, sizeof Min);     scanf( %d%d , &m, &n);     for (int i = (0), _end_ = (m); i != _end_; ++i) {       scanf( %d , &all[i].first.first), --all[i].first.first;       static int nn;       scanf( %d , &nn);       all[i].first.second = tmp[i] = 0;       owaski[all[i].first.first].push_back(i);       for (int j = (0), _end_ = (nn); j != _end_; ++j) {         static int first;         scanf( %d , &first);         if (first == -1)           ++all[i].first.second, ++tmp[i];         else           --first, ++all[i].second, yyt[first].push_back(i),               zzj[i].push_back(first);       }     }     for (int i = (0), _end_ = (m); i != _end_; ++i)       if (!all[i].second) chkmin(Min[all[i].first.first], all[i].first.second);     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         q;     for (int i = (0), _end_ = (n); i != _end_; ++i)       if (Min[i] < oo) q.push(make_pair(Min[i], i));     while (!q.empty()) {       int first = q.top().second;       q.pop();       if (vis[first]) continue;       vis[first] = 1;       for (int i = (0), _end_ = ((int((yyt[first]).size()))); i != _end_; ++i) {         const int &second = yyt[first][i];         all[second].first.second =             min(all[second].first.second + Min[first], Max_val);         if (!--all[second].second &&             chkmin(Min[all[second].first.first], all[second].first.second))           q.push(               make_pair(Min[all[second].first.first], all[second].first.first));       }     }     memset(vis, 0, sizeof vis);     memset(Max, 0, sizeof Max);     for (int i = (0), _end_ = (n); i != _end_; ++i)       if (Min[i] == oo) Min[i] = Max[i] = -1;     for (int i = (0), _end_ = (n); i != _end_; ++i) {       find(i);       printf( %d %d n , Min[i], Max[i]);     }     return 0;   }   