Language: C++

#include <bits/stdc++.h>

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

template <typename T>
class graph {
 public:
  struct edge {
    int from;
    int to;
    T cost;
  };

  vector<edge> edges;
  vector<vector<int>> g;
  int n;

  graph(int _n) : n(_n) {
    g.resize(n);
  }

  virtual int add(int from, int to, T cost) = 0;
};

template <typename T>
class digraph : public graph<T> {
 public:
  using graph<T>::edges;
  using graph<T>::g;
  using graph<T>::n;

  digraph(int _n) : graph<T>(_n) {
  }

  int add(int from, int to, T cost = 1) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    int id = (int) edges.size();
    g[from].push_back(id);
    edges.push_back({from, to, cost});
    return id;
  }

  digraph<T> reverse() const {
    digraph<T> rev(n);
    for (auto &e : edges) {
      rev.add(e.to, e.from, e.cost);
    }
    return rev;
  }
};

template <typename T>
vector<int> find_scc(const digraph<T> &g, int &cnt) {
  digraph<T> g_rev = g.reverse();
  vector<int> order;
  vector<bool> was(g.n, false);
  function<void(int)> dfs1 = [&](int v) {
    was[v] = true;
    for (int id : g.g[v]) {
      auto &e = g.edges[id];
      int to = e.to;
      if (!was[to]) {
        dfs1(to);
      }
    }
    order.push_back(v);
  };
  for (int i = 0; i < g.n; i++) {
    if (!was[i]) {
      dfs1(i);
    }
  }
  vector<int> c(g.n, -1);
  function<void(int)> dfs2 = [&](int v) {
    for (int id : g_rev.g[v]) {
      auto &e = g_rev.edges[id];
      int to = e.to;
      if (c[to] == -1) {
        c[to] = c[v];
        dfs2(to);
      }
    }
  };
  cnt = 0;
  for (int id = g.n - 1; id >= 0; id--) {
    int i = order[id];
    if (c[i] != -1) {
      continue;
    }
    c[i] = cnt++;
    dfs2(i);
  }
  return c;
  // c[i] <= c[j] for every edge i -> j
}

int n, m;

int main() {
  cin >> n >> m;
  digraph<int> g(n);
  range(i, 0, m) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g.add(u, v);
  }
  int cnt = 0;
  vector<int> scc = find_scc(g, cnt);
  vector<vector<int>> st(cnt);
  range(i, 0, n) st[scc[i]].push_back(i);
  range(i, 0, cnt) {
    if(st[i].size() == 1) continue;
    vector<int> que;
    vector<int> alive(n);
    int c = st[0];
    que.push_back(c);
    for(int b = 0; b < (int) que.size(); b++) {
      int v = que[b];
      for(int p : g.g[v]) {
        int u = g.edges[p].to;
        if(scc[u] != i || alive[u]) continue;
        que.push_back(u);
        break;
      }
    }
    swap(que, st[i]);
    vector<int> cur;
    vector<int> dep(n, -1);
    range(j, 0, (int) st[i].size()) {
      dep[st[i][j]] = j;
      int v = st[i][j];
      cur.push_back(v);
      int s = -1;
      for(int p : g.g[v]) {
        int u = g.edges[p].to;
        if(dep[u] != -1 && (s == -1 || dep[u] > dep[s])) s = u;
      }
      if(s == -1) continue;
      vector<int> res;
      husk(ii, cur.size() - 1, -1) {
        res.push_back(cur[ii]);
        if(cur[ii] == s) break;
      }
      cout << res.size() << endl;
      for(int v : res) cout << v + 1 << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:119:17: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'int' in initialization
  119 |     int c = st[0];
      |                 ^