Language: C++

#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



////////////////////////////////////////////////////////////////////

template<typename T>
struct edge {
  int to, from;T cost;
  edge(int to) : from(-1), to(to), cost(-1) {}
  edge(int to, T cost) : from(-1), to(to), cost(cost) {}
  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};
template<typename T>
using edges = vector<edge<T>>;
template<typename T>
using graph = vector<edges<T>>;
template<typename T>
using matrix = vector<vector<T>>;

template<typename T>
bool compByCost(const edge<T>& left, const edge<T>& right){
  return left.cost < right.cost; 
}

vector<int> prevn(1100);

template<typename T>
vector<T> dijkstra(int s, graph<T> &g){
  vector<T> dist(g.size()+10, INF);dist[s] = 0;rep(i,1100)prevn[i] = -1;prevn[s] = INF;
  priority_queue<P, vector<P>, greater<P>> que;que.push(P(0,s));
  while(!que.empty()){
    P p = que.top();que.pop();
    int v = p.second;
    if(dist[v] < p.first)continue;
    rep(i, g[v].size()){
      edge<T> e = g[v][i];
      if(dist[e.to] > dist[v] + e.cost){
        dist[e.to] = dist[v] + e.cost;
        prevn[e.to] = v;
        que.push(P(dist[e.to], e.to));
      }
    }
  }
  return dist;
}

#define dijkstra dijkstra<int>

////////////////////////////////////////////////////////////////////


int n,m;graph<int> g(1100), h(1100);
vector<int> d1, d2;

signed main(){
  cin>>n>>m;
  rep(i,m){
    int a,b;cin>>a>>b;a--;b--;
    g[a].push_back(edge<int>(b, 1));
    h[b].push_back(edge<int>(a, 1));
  }
  int ans = INF, from, to;
  rep(i,n){
    d1 = dijkstra(i, g);
    d2 = dijkstra(i, h);
    
    rep(j,n){
      if(i == j)continue;
      if(chmin(ans, d1[j]+d2[j])){
        from = i;to = j;
      }
    }
  }
  if(ans >= INF){
    cout << -1 << endl;return 0;
  }
  dijkstra(from, g);
  stack<int> st;st.push(to);
  queue<int> ret;
  while(st.top != INF && prevn[st.top()] != INF){
    st.push(prevn[st.top()]);
  }
  while(!st.empty()){
    ret.push(st.top()+1);st.pop();
  }
  dijkstra(to, g);st.push(prevn[from]);
  while(prevn[st.top()] != INF && prevn[prevn[st.top()]] != INF){
    st.push(prevn[st.top()]);
  }
  while(!st.empty()){
    ret.push(st.top()+1);st.pop();
  }
  cout << ret.size() << endl;
  while(!ret.empty()){
    cout << ret.front() << endl;ret.pop();
  }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:96:16: error: invalid operands of types '<unresolved overloaded function type>' and 'const ll' {aka 'const long long int'} to binary 'operator!='
   96 |   while(st.top != INF && prevn[st.top()] != INF){
      |         ~~~~~~ ^~ ~~~
      |            |      |
      |            |      const ll {aka const long long int}
      |            <unresolved overloaded function type>