제출 #1257939

#제출 시각아이디문제언어결과실행 시간메모리
1257939duyanhloveavPotemkin cycle (CEOI15_indcyc)C++20
30 / 100
1095 ms2236 KiB
#include <bits/stdc++.h>
using namespace std;

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)

using ll = long long;

const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;

int n, m;
vector<vector<int>> adj;
vector<array<int, 2>> e;

namespace SUB1 {
  bool check() {
    return (n <= 10 && m <= 45);
  }

  vector<int> par;
  vector<char> used;

  void dfs(int u, int s, int h) {
    if (h >= 4) {
      vector<int> res;
      int cur = u;
      while (cur != 0) {
        res.push_back(cur);
        cur = par[cur];
      }
      reverse(res.begin(), res.end());
      if (binary_search(adj[res.back()].begin(), adj[res.back()].end(), res.front())) {
        int k = (int)res.size();
        bool f = false;
        for (int i = 0; i < k && !f; ++i) {
          for (int j = i + 1; j < k; ++j) {
            if (j == i + 1) continue;
            if (i == 0 && j == k - 1) continue;
            if (binary_search(adj[res[i]].begin(), adj[res[i]].end(), res[j])) {
              f = true;
              break;
            }
          }
        }
        if (!f) {
          for (int v : res) cout << v << " ";
          cout << "\n";
          exit(0);
        }
      }
    }

    used[u] = 1;
    for (int v : adj[u]) {
      if (!used[v]) {
        par[v] = u;
        dfs(v, s, h + 1);
      }
    }
    used[u] = 0;
  }

  void solve() {
    par.assign(n + 1, 0);
    used.assign(n + 1, 0);
    for (int i = 1; i <= n; ++i) sort(adj[i].begin(), adj[i].end());
    for (int i = 1; i <= n; ++i) {
      par[i] = 0;
      dfs(i, i, 1);
    }
    cout << "no\n";
  }
}

namespace SUBFULL {
  void solve() {
    vector<vector<bool>> check(n + 1, vector<bool>(n + 1));
    for (int i = 1; i <= n; ++i) {
      for (auto &j : adj[i]) {
        check[i][j] = true;
      }
    }
    vector<int> dist(n + 1), par(n + 1);
    deque<int> q;
    sort(begin(e), end(e));
    e.resize(unique(begin(e), end(e)) - begin(e));
    for (auto &x : e) {
      fill(begin(dist), end(dist), -1);
      fill(begin(par), end(par), -1);
      while (!q.empty()) {
        q.pop_back();
      }
      dist[x[0]] = 0;
      q.push_back(x[0]);
      bool f = false;
      while (!q.empty()) {
        int u = q.front();
        q.pop_front();
        for (auto &v : adj[u]) {
          if ((u == x[0] && v == x[1]) || (u == x[1] && v == x[0])) {
            continue;
          }
          if (!~dist[v]) {
            dist[v] = dist[u] + 1;
            par[v] = u;
            if (v == x[1]) {
              f = true;
              break;
            }
            q.push_back(v);
          }
        }
        if (f) {
          break;
        }
      }
      if (f) {
        int len = dist[x[1]];
        if (len >= 3) {
          int s = x[1];
          vector<int> res;
          while (~s) {
            res.push_back(s);
            s = par[s];
          }
          reverse(begin(res), end(res));
          bool f = false;
          for (int i = 0; i < (int) (res.size()) && !f; ++i) {
            for (int j = i + 1; j < (int) (res.size()); ++j) {
              if ((i == 0 && j == (int) (res.size()) - 1) || (j == i + 1)) {
                continue;
              }
              if (check[res[i]][res[j]]) {
                f = true;
                break;
              }
            }
          }
          if (!f) {
            for (auto &x : res) {
              cout << x << " ";
            }
            return;
          }
        }
      }
    }
    cout << "no\n";
  }
}

void _27augain(void) {
  cin >> n >> m;
  adj.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    e.push_back({u, v});
  }
  SUB1::solve();
}

int32_t main(void) {
#define task "27augain"
  cin.tie(0)->sync_with_stdio(0);
  for (string iext : {"in", "inp"}) {
    if (fopen((task "." + iext).c_str(), "r")) {
      freopen((task "." + iext).c_str(), "r", stdin);
      freopen(task ".out", "w", stdout);
    }
  }
  int testcase = 1;
  // cin >> testcase;
  while (testcase--) {
    _27augain();
  }
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

indcyc.cpp: In function 'int32_t main()':
indcyc.cpp:172:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  172 |       freopen((task "." + iext).c_str(), "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
indcyc.cpp:173:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  173 |       freopen(task ".out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...