This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <fstream>
#include <bitset>
#include <cassert>
#include <vector>
#include <queue>
#include <algorithm>
#define rep(i, n) for (int i=0; i<(n); i++)
#define INF 1145141919
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
int N, M;
vector<int> G[1000];
bool G2[1000][1000];
int A[1000], pre[1000];
signed main() {
  cin >> N >> M;
  rep(i, N) G2[i][i] = true;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].pb(b);
    G[b].pb(a);
    G2[a][b] = G2[b][a] = true;
  }
  rep(s, N) {
    rep(i, N) A[i] = -1;
    queue<int> q;
    rep(t, N) for (int t : G[s]) {
      pre[t] = s, A[t] = t;
      q.push(t);
    }
    while (!q.empty()) {
      int x = q.front(); q.pop();
      for (int t : G[x]) {
        if (t == s) continue;
        if (A[t] == -1) {
          A[t] = A[x], pre[t] = x;
          q.push(t);
        }
        else {
          int a = A[x], b = A[t];
          if (G2[a][b]) continue;
          vector<int> left, right;
          while (x != s) {
            left.pb(x);
            x = pre[x];
          }
          while (t != s) {
            right.pb(t);
            t = pre[t];
          }
          reverse(all(right));
          left.pb(s);
          for (int r : right) left.pb(r);
          for (int x : left) cout << x+1 << " "; cout << "\n";
          return 0;
        }
      }
    }
  }
  cout << "no\n";
  return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |