func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> adj[3010], vert;   map<int, vector<pair<int, int> > > query[3010];   int ans[400010], vis[3010], in_cycle;   void dfs(int v, int par) {     vis[v] = 1;     if (!in_cycle) vert.push_back(v);     if (query[par].count(v)) {       vector<pair<int, int> > *ptr = &query[par][v];       int vert_size = vert.size();       for (auto p : *ptr) {         ans[p.second] =             ((p.first > vert_size || in_cycle) ? -1 : vert[p.first - 1]);       }     }     for (int i = 0; i < adj[v].size(); ++i) {       int t = adj[v][i];       if (vis[t] == 0)         dfs(t, par);       else if (vis[t] == 1) {         ++in_cycle;         ++vis[t];       }     }     if (v == vert.back()) vert.pop_back();     if (vis[v] > 1)       --in_cycle;     else       vis[v] = 2;   }   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back(v);     }     for (int i = 1; i <= n; ++i) {       sort(adj[i].begin(), adj[i].end());     }     for (int i = 0; i < q; ++i) {       int s, t, k;       scanf( %d %d %d , &s, &t, &k);       query[s][t].push_back(make_pair(k, i));     }     for (int i = 0; i < q; ++i) ans[i] = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) vis[j] = 0;       in_cycle = 0;       dfs(i, i);     }     for (int i = 0; i < q; ++i) printf( %d n , ans[i]);     return 0;   }   