Submission #36015

# Submission time Handle Problem Language Result Execution time Memory
36015 2017-12-04T08:28:37 Z funcsr Potemkin cycle (CEOI15_indcyc) C++14
50 / 100
1000 ms 5652 KB
#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
1 Correct 0 ms 3028 KB Output is correct
2 Correct 0 ms 3028 KB Output is correct
3 Correct 0 ms 3028 KB Output is correct
4 Correct 0 ms 3028 KB Output is correct
5 Correct 0 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3028 KB Output is correct
2 Correct 0 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3028 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 3160 KB Output is correct
2 Correct 0 ms 3160 KB Output is correct
3 Correct 13 ms 3160 KB Output is correct
4 Correct 663 ms 3312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 259 ms 3284 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 236 ms 4040 KB Output is correct
2 Correct 63 ms 3556 KB Output is correct
3 Execution timed out 1000 ms 4036 KB Execution timed out
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 5652 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 4744 KB Execution timed out
2 Halted 0 ms 0 KB -