func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int n, m, w, o[N], K[N], P[N], C[N];   int vis[N];   vector<int> adj[N];   void bfs(int src) {     for (int i = 0; i <= n; ++i) vis[i] = -1;     queue<int> q, qw;     q.push(src);     qw.push(0);     vis[src] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       int w = qw.front();       qw.pop();       for (auto v : adj[u]) {         if (vis[v] == -1) {           vis[v] = w + 1;           q.push(v);           qw.push(w + 1);         }       }     }   }   int q;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d , &w);     for (int i = 0; i < w; ++i) {       int c, k, p;       scanf( %d%d%d , &c, &k, &p);       o[i] = i;       K[i] = k;       P[i] = p;       C[i] = c;     }     sort(o, o + w, [](int i, int j) { return P[i] < P[j]; });     scanf( %d , &q);     while (q--) {       int g, r, a;       scanf( %d%d%d , &g, &r, &a);       int L = 0, R = n;       bfs(g);       while (L < R) {         int M = (L + R) / 2;         long long totalCost = 0;         int shovels = 0;         for (int i = 0; i < w; ++i) {           int id = o[i];           if (vis[C[id]] != -1 && vis[C[id]] <= M) {             int need = min(r - shovels, K[id]);             totalCost += 1ll * need * P[id];             shovels += need;             if (shovels >= r) break;           }         }         if (totalCost > a || shovels < r) {           L = M + 1;         } else {           R = M;         }       }       if (L == n) {         L = -1;       }       printf( %d n , L);     }   }   