Submission #260001

# Submission time Handle Problem Language Result Execution time Memory
260001 2020-08-08T22:22:04 Z Haunted_Cpp Potemkin cycle (CEOI15_indcyc) C++17
30 / 100
1000 ms 24064 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 5e3 + 5;

int g[MAX_N][MAX_N], dp[MAX_N][MAX_N], nxt[MAX_N][MAX_N];

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = (i == j ? 0 : 1e9);
      nxt[i][j] = j;
    }
  }
  for (int i = 0; i < m; i++) {
    int st, et;
    cin >> st >> et;
    --st; --et;
    g[st][et] = g[et][st] = 1;
    dp[st][et] = dp[et][st] = 1;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if(dp[i][j] > dp[i][k] + dp[k][j]) {
          dp[i][j] = dp[i][k] + dp[k][j];
          nxt[i][j] = nxt[i][k];
        }
      }
    }
  }
  auto get_path = [&](int source, int destination) {
    vector<int> path;
    while(source != destination) {
      path.emplace_back(source);
      source = nxt[source][destination];
    }
    return path;
  };
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (dp[i][j] > 1e7 || dp[j][k] > 1e7 || dp[k][i] > 1e7) continue;
        vector<int> A = get_path(i, j);
        vector<int> B = get_path(j, k);
        vector<int> C = get_path(k, i);
        vector<int> all;    
        for (auto to : A) all.emplace_back(to);
        for (auto to : B) all.emplace_back(to);
        for (auto to : C) all.emplace_back(to);
        vector<int> chk = all;
        sort(chk.begin(), chk.end());
        chk.erase(unique(chk.begin(), chk.end()), chk.end());
        if ((int)chk.size() != (int)all.size() || (int)chk.size() < 4) {
          continue;
        }
          
        
        if (chk.size() < 4) continue;
        bool valid = true;
        for (int cur = 0; cur < (int) all.size(); cur++) {
          int cnt = 0;
          for (int to = 0; to < (int) all.size(); to++) {
            if (to == cur) continue;
            cnt += (dp[all[cur]][all[to]] == 1);
          }
          valid &= (cnt == 2);
        }
        if (valid) {
          for (auto to : all) cout << to + 1 << ' ';
          cout << '\n';
          return 0;
        }

      }
    }
  }
  cout << "no" << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 1664 KB Expected integer, but "no" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1054 ms 5112 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 4992 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 24064 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 23808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 8064 KB Time limit exceeded
2 Halted 0 ms 0 KB -