Language: C++

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>

int n, m, a, b, vt[1005];
vector<int> gr[1005], tmp, ans;

void dfs(int p) {
	tmp.push_back(p);
	vt[p] = 1;
	for(auto x:gr[p]) {
		if(x == tmp[0]) {
			if(ans.empty() || tmp.size() < ans.size()) ans = tmp;
		} else if (!vt[p]) {
			dfs(v);
		}
	}
	tmp.pop_back();
}

int main() {
	cin >> n >> m;
	while(m--) {
		cin >> a >> b;
		gr[a].push_back(b);
	}
	for(i=1; i<=n; i++) {
		memset(vt, 0, sizeof(vt));
		tmp.clear();
		dfs(i);
	}
	if(ans.empty()) {puts("-1"); return 0;}
	cout << ans.size() << endl;
	for(auto x:ans) cout << x << endl;
	return 0;
}

Compiler output:
a.cc:7:1: error: 'vector' does not name a type
    7 | vector<int> gr[1005], tmp, ans;
      | ^~~~~~
a.cc: In function 'void dfs(int)':
a.cc:10:9: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   10 |         tmp.push_back(p);
      |         ^~~
      |         tm
a.cc:12:20: error: 'gr' was not declared in this scope
   12 |         for(auto x:gr[p]) {
      |                    ^~
a.cc:14:28: error: 'ans' was not declared in this scope; did you mean 'abs'?
   14 |                         if(ans.empty() || tmp.size() < ans.size()) ans = tmp;
      |                            ^~~
      |                            abs
a.cc:16:29: error: 'v' was not declared in this scope
   16 |                         dfs(v);
      |                             ^
a.cc: In function 'int main()':
a.cc:23:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   23 |         cin >> n >> m;
      |         ^~~
      |         std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:26:17: error: 'gr' was not declared in this scope
   26 |                 gr[a].push_back(b);
      |                 ^~
a.cc:28:13: error: 'i' was not declared in this scope
   28 |         for(i=1; i<=n; i++) {
      |             ^
a.cc:30:17: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   30 |                 tmp.clear();
      |                 ^~~
      |                 tm
a.cc:33:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
   33 |         if(ans.empty()) {puts("-1"); return 0;}
      |            ^~~
      |            abs
a.cc:34:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   34 |         cout << ans.size() << endl;
      |         ^~~~
      |         std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:34:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   34 |         cout << ans.size() << endl;
      |                 ^~~
      |                 abs
a.cc:34:31: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   34 |         cout << ans.size() << endl;
      |                               ^~~~
      |                               std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~