Language: C++

#include <bits/stdc++.h>//Atcorder 142 
#include <vector>
#include <iostream>
#include <utility>
#define chmin(x, y) x = min(x , y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long int ll;

const ll INF = 1e12;

int N, M;
vector<vector<int> > Graph;
vector<int> bfs(int sv){
    vector<int> dist(n, INF), pre(n, -1);
    vector<int> q;
    dist[sv] = 0;
    q.push_back(sv);
    while(!q.empty()){
        int v = q.front() :q.pop();
        for (int u : Graph[v]){
            if(dist[u] == INF) continue;
            pre[u] = v;
            dist[u] = dist[v]+1;
            q.push(u);
        }
    }
    pair<int ,int > best(INF, -1);
    rep(i,N){
        if( sv == v) continue;
        for(int u: Graph[v]){
            if(u == sv){
            best = min(best, make_pair(dist[u],u);
            }
        }
    }
    if (best.first == INF) return vector<int>(n+1);
    int v = best.second;
    vector<int> res;
    while (v != -1){
        res.push_back(v);
        v = pre[v]
    }
    return res;
}


void input() {
    cin >> N >> M;
    rep(i, M) {
        int a, b;cin >> a >> b;a--;b--;
        Graph[a].push_back(b);
    }
}

void solve () {
    input();
    auto ans (n+1);
    rep(i, n){
        vi now = dfs(i);
        if(now.size() < ans.size()) ans = now;
    }
    if(ans.size() == N+1){
        cout <<-1 << endl;
        return ;
    }
    cout << ans.size() << endl;
    for (int v:ans){
        cout << v << endl;
    }
    return;
}

int main () {
    solve();
    return 0;
}



Compiler output:
a.cc: In function 'std::vector<int> bfs(int)':
a.cc:18:22: error: 'n' was not declared in this scope
   18 |     vector<int> dist(n, INF), pre(n, -1);
      |                      ^
a.cc:23:27: error: expected ',' or ';' before ':' token
   23 |         int v = q.front() :q.pop();
      |                           ^
a.cc:28:15: error: 'class std::vector<int>' has no member named 'push'
   28 |             q.push(u);
      |               ^~~~
a.cc:33:19: error: 'v' was not declared in this scope
   33 |         if( sv == v) continue;
      |                   ^
a.cc:34:26: error: 'v' was not declared in this scope
   34 |         for(int u: Graph[v]){
      |                          ^
a.cc:36:50: error: expected ')' before ';' token
   36 |             best = min(best, make_pair(dist[u],u);
      |                       ~                          ^
      |                                                  )
a.cc:45:19: error: expected ';' before '}' token
   45 |         v = pre[v]
      |                   ^
      |                   ;
   46 |     }
      |     ~              
a.cc: In function 'void solve()':
a.cc:61:15: error: 'n' was not declared in this scope
   61 |     auto ans (n+1);
      |               ^
a.cc:63:9: error: 'vi' was not declared in this scope; did you mean 'i'?
   63 |         vi now = dfs(i);
      |         ^~
      |         i
a.cc:64:12: error: 'now' was not declared in this scope; did you mean 'pow'?
   64 |         if(now.size() < ans.size()) ans = now;
      |            ^~~
      |            pow