Language: C++

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <cassert>

using namespace std;

int in_stack[1000];
bool used[1000];
vector <int> edges[1000];
//int global_min_cycle_len;

int dfs_cycle_len(int cur){
    int min_cycle_len = INT_MAX;
    used[cur] = true;
    for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i];
        if(!used[next]){
            in_stack[next] = in_stack[cur] + 1;
            min_cycle_len = min(min_cycle_len, dfs_cycle_len(next));
        } else {
            if(in_stack[next] >= 0){
                min_cycle_len = min(min_cycle_len, in_stack[cur] - in_stack[next] + 1);
            }
        }
    }
    in_stack[cur] = -1;
    return min_cycle_len;
}

pair<int, int> dfs(int cur, int cycle_len){
    //cout << cur << " " << in_stack[cur] << endl;
    used[cur] = true;
    for(int i = 0; i < edges[cur].size(); i++){
        int next = edges[cur][i];
        if(!used[next]){
            in_stack[next] = in_stack[cur] + 1;
            auto ans = dfs(next, cycle_len);
            if(ans.first >= 0){
                return ans;
            }
        } else {
            if(in_stack[next] >= 0){
                if(cycle_len == in_stack[cur] - in_stack[next] + 1){
                    return make_pair(next, cur);
                }
            }
        }
    }
    in_stack[cur] = -1;
    return make_pair(-1, -1);
}

int main(){
    int N;
    int M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int A;
        int B;
        cin >> A >> B;
        edges[A - 1].push_back(B - 1);
    }

    for(int i = 0; i < N; i++){
        in_stack[i] = -1;
    }
    int ans_len = INT_MAX;
    int dfs_start;
    for(int i = 0; i < N; i++){
        if(!used[i]){
            in_stack[i] = 0;
            int cycle_len = dfs_cycle_len(i);
            if(cycle_len != INT_MAX){
                ans_len = cycle_len;
                dfs_start = i;
                break;
            }
        }
    }
    if(ans_len == INT_MAX){
        cout << -1 << endl;
        return 0;
    }
    //cout << ans_len << " " << dfs_start << endl;
    for(int i = 0; i < N; i++){
        used[i] = false;
        in_stack[i] = -1;
    }
    in_stack[dfs_start] = 0;
    auto cycle_pair = dfs(dfs_start, ans_len);
    //cout << cycle_pair.first << " " << cycle_pair.second << endl;
    vector <int> ans;
    //cout << cycle_pair.first << endl;
    if(cycle_pair.first >= 0){
        vector <pair <int, int> > tmp;
        for(int i = 0; i < N; i++){
            tmp.push_back(make_pair(in_stack[i], i));
        }
         sort(tmp.begin(), tmp.end());
        bool in_cycle = false;
        for(int i = 0; i < N; i++){
            //cout << tmp[i].first << " " << tmp[i].second << endl;
            if(tmp[i].second == cycle_pair.first){
                in_cycle = true;
            }
            if(in_cycle){
                ans.push_back(tmp[i].second);
            }
            if(tmp[i].second == cycle_pair.second){
                break;
            }
        }
    }

    if(ans.size() == 0){
      cout << 1 / ans.size() << endl;
    }
    cout << ans[i].size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] + 1 << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:130:17: error: 'i' was not declared in this scope
  130 |     cout << ans[i].size() << endl;
      |                 ^