func_code_string: #include <bits/stdc++.h>   using namespace std;   const int max_n = 1e5 + 10;   const long long inf = 10000000000000000;   vector<int> adj[max_n];   vector<long long> cst[max_n];   vector<int> arr[max_n];   vector<long long> closest[max_n];   void cmp_closest(int i) {     int s = arr[i].size();     if (s > 0) {       closest[i].reserve(s);       closest[i][s - 1] = arr[i][s - 1] + 1;       for (int j = s - 2; j >= 0; --j) {         if (arr[i][j] + 1 != arr[i][j + 1]) {           closest[i][j] = arr[i][j] + 1;         } else {           closest[i][j] = closest[i][j + 1];         }       }     }   }   int n, m;   void add_edge(int a, int b, int c) {     adj[a].push_back(b);     cst[a].push_back(c);     adj[b].push_back(a);     cst[b].push_back(c);   }   void read() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b, c;       cin >> a >> b >> c;       --a;       --b;       add_edge(a, b, c);     }     for (int i = 0; i < n; ++i) {       int k;       cin >> k;       for (int j = 0; j < k; ++j) {         long long t;         cin >> t;         arr[i].push_back(t);       }       cmp_closest(i);     }   }   long long dist[max_n];   struct cmpl {     inline bool operator()(int a, int b) const {       return (dist[a] < dist[b] || (dist[a] == dist[b] && a < b));     }   };   int cost(int u, size_t i) {     vector<int>::iterator it = lower_bound(arr[u].begin(), arr[u].end(), dist[u]);     if (it != arr[u].end() && *it == dist[u]) {       return cst[u][i] + (closest[u][it - arr[u].begin()]) - dist[u];     } else {       return cst[u][i];     }   }   set<int, cmpl> pq;   int main() {     read();     for (int i = 1; i < n; ++i) {       dist[i] = inf;     }     pq.insert(0);     int res = -1;     while (!pq.empty()) {       int curr = *pq.begin();       pq.erase(pq.begin());       if (curr == n - 1) {         res = dist[curr];         break;       } else {         for (size_t i = 0; i < adj[curr].size(); ++i) {           int v = adj[curr][i];           int c = cost(curr, i);           if (dist[curr] + c < dist[v]) {             pq.erase(v);             dist[v] = dist[curr] + c;             pq.insert(v);           }         }       }     }     cout << res << endl;     return 0;   }   