Submission #1059314

# Submission time Handle Problem Language Result Execution time Memory
1059314 2024-08-14T20:59:29 Z MilosMilutinovic Potemkin cycle (CEOI15_indcyc) C++14
10 / 100
1000 ms 119636 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1000;

bool c[N][N];
vector<int> g[N];
bitset<N> bs[N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m; 
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    c[x][y] = true;
    c[y][x] = true;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int k = 0; k < n; k++) {
    vector<bool> del(n);
    del[k] = true;
    for (int i : g[k]) {
      del[i] = true;
    }
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    vector<int> sz(n, 1);
    function<int(int)> Root = [&](int x) {
      return p[x] == x ? x : p[x] = Root(p[x]);
    };
    auto Merge = [&](int x, int y) {
      x = Root(x);
      y = Root(y);
      if (x == y) {
        return;
      }
      if (sz[x] < sz[y]) {
        swap(x, y);
      }
      sz[x] += sz[y];
      p[y] = x;
    };
    for (int i = 0; i < n; i++) {
      if (del[i]) {
        continue;
      }
      for (int j : g[i]) {
        if (del[j]) {
          continue;
        }
        Merge(i, j);
      }
    }
    for (int i = 0; i < n; i++) {
      if (!del[i]) {
        continue;
      }
      for (int j : g[i]) {
        if (del[j]) {
          continue;
        }
        bs[k][i][Root(j)] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j : g[i]) {
      if (i > j) {
        continue;
      }
      for (int k : g[g[i].size() < g[j].size() ? i : j]) {
        if (i == k || j == k || !c[i][k] || !c[j][k]) {
          continue;
        }
        if ((bs[k][i] & bs[k][j]).count() == 0) {
          continue;
        }
        vector<bool> del(n);
        del[k] = true;
        for (int p : g[k]) {
          if (p != i && p != j) {
            del[p] = true;
          }
        }
        vector<int> p(n, -1);
        vector<int> que(1, i);
        vector<int> d(n, -1);
        d[i] = 0;
        for (int b = 0; b < (int) que.size(); b++) {
          int i = que[b];
          for (int j : g[i]) {
            if (del[j]) {
              continue;
            }
            if (d[j] == -1) {
              p[j] = i;
              d[j] = d[i] + 1;
              que.push_back(j);
            }
          }
        }
        if (p[j] == -1) {
          assert(false);
          continue;
        }
        vector<int> seq;
        for (int v = j; v != -1; v = p[v]) {
          seq.push_back(v);
        }
        seq.push_back(k);
        for (int i = 0; i < (int) seq.size(); i++) {
          cout << seq[i] + 1 << " ";
        }
        cout << '\n';
        return 0;
      }
    }
  }
  cout << "no" << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Too short sequence
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Too short sequence
2 Incorrect 0 ms 348 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1628 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1884 KB Too short sequence
2 Incorrect 2 ms 1884 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 11100 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 8792 KB Too short sequence
2 Incorrect 24 ms 8796 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 874 ms 119636 KB Too short sequence
2 Correct 398 ms 92244 KB Too short sequence
3 Incorrect 858 ms 119120 KB Wrong answer on graph without induced cycle
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 372 ms 66132 KB Too short sequence
2 Incorrect 359 ms 67408 KB Wrong answer on graph without induced cycle
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 2676 KB Too short sequence
2 Execution timed out 1085 ms 1928 KB Time limit exceeded
3 Halted 0 ms 0 KB -