func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int read() {     char ch =    ;     int x = 0;     bool flag = false;     while (!isdigit(ch)) {       if (ch ==  - ) flag = true;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return flag ? -x : x;   }   struct heap {     vector<pair<int, int> > v;     int loc[N];     heap() {       v.push_back(make_pair(-1, -1));       memset(loc, -1, sizeof loc);     }     void push(pair<int, int> p) {       int cur;       cur = v.size();       loc[p.second] = cur;       v.push_back(p);       while (v[cur] < v[cur >> 1]) {         swap(v[cur], v[cur >> 1]);         swap(loc[v[cur].second], loc[v[cur >> 1].second]);         cur >>= 1;       }     }     void pop() {       if (empty()) return;       swap(v[1], v.back());       loc[v[1].second] = 1;       loc[v.back().second] = -1;       v.pop_back();       int cur = 1;       while ((cur << 1) < v.size()) {         if ((cur << 1) + 1 == v.size()) {           if (v[cur] > v[cur << 1])             swap(v[cur], v[cur << 1]),                 swap(loc[v[cur].second], loc[v[cur << 1].second]);           break;         }         if (v[cur] < min(v[cur << 1], v[(cur << 1) + 1])) break;         if (v[cur << 1] < v[(cur << 1) + 1]) {           swap(v[cur], v[cur << 1]);           swap(loc[v[cur].second], loc[v[cur << 1].second]);           cur <<= 1;         } else {           swap(v[cur], v[(cur << 1) + 1]);           swap(loc[v[cur].second], loc[v[(cur << 1) + 1].second]);           cur = (cur << 1) + 1;         }       }     }     pair<int, int> top() { return v[1]; }     bool empty() { return v.size() == 1; }   };   int n, m;   vector<int> bad[N];   vector<pair<int, int> > v[N];   int d[N];   heap pq;   int main() {     n = read(), m = read();     for (int i = 0; i < m; i++) {       int a = read(), b = read(), c = read();       --a, --b;       v[a].push_back(make_pair(b, c));       v[b].push_back(make_pair(a, c));     }     for (int i = 0; i < n; i++) {       int num = read();       while (num--) {         bad[i].push_back(read());       }     }     for (int i = 0; i < n; i++) d[i] = 0x3f3f3f3f;     d[0] = 0;     pq.push(make_pair(0, 0));     while (!pq.empty()) {       pair<int, int> tp = pq.top();       pq.pop();       int t = tp.first;       int cur = tp.second;       if (t != d[cur]) continue;       int j = 0;       while (j < bad[cur].size() && bad[cur][j] < t) j++;       while (j < bad[cur].size() && bad[cur][j] == t) t++, j++;       for (int i = 0; i < v[cur].size(); i++) {         int to = v[cur][i].first, cost = v[cur][i].second;         if (t + cost < d[to]) {           d[to] = t + cost;           pq.push(make_pair(d[to], to));         }       }     }     if (d[n - 1] >= 0x3f3f3f3f)       puts( -1 );     else       cout << d[n - 1] << endl;     return 0;   }   