QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417347#4513. Slide ParadeWhicyCompile Error//C++203.0kb2024-05-22 17:48:402024-05-22 17:48:40

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 17:48:40]
  • 评测
  • [2024-05-22 17:48:40]
  • 提交

answer

#include <_timeval.h>
#include <chrono>
#include <iostream>
#include <ostream>
#include <vector>
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  int T;
  std::cin >> T;
  for (int TC = 1; TC <= T; TC++) {
    std::cout << "Case #" << TC << ": ";
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> ed(n), rved(n);
    for (int i = 0; i < m; i++) {
      int u, v;
      std::cin >> u >> v;
      ed[--u].push_back(--v);
      rved[v].push_back(u);
    }
    std::vector<bool> con1(n), con2(n);
    int lst;
    auto scc1 = [&](auto scc1, int u) -> void {
      con1[u] = 1;
      for (auto v : ed[u])
        if (!con1[v])
          scc1(scc1, v);
      lst = u;
    };
    bool imp = 0;
    scc1(scc1, 0);
    for (int i = 0; i < n; i++) {
      if (!con1[i]) {
        imp = 1;
        break;
      }
    }
    auto scc2 = [&](auto scc2, int u) -> void {
      con2[u] = 1;
      for (auto v : rved[u])
        if (!con2[v])
          scc2(scc2, v);
    };
    scc2(scc2, lst);
    for (int i = 0; i < n; i++) {
      if (!con2[i]) {
        imp = 1;
        break;
      }
    }
    if (imp) {
      std::cout << "IMPOSSIBLE\n";
      continue;
    }
    std::vector<int> lnk(n, -1), vis(n, 0);
    auto dfs = [&](const auto &dfs, const int &u, std::vector<bool> &vis) -> bool {
      for (int v : ed[u]) {
        if (vis[v])
          continue;
        vis[v] = 1;
        if (!~lnk[v] || dfs(dfs, lnk[v], vis)) {
          lnk[v] = u;
          return true;
        }
      }
      return false;
    };
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      std::vector<bool> vis(n, 0);
      if (dfs(dfs, i, vis))
        cnt++;
    }
    if (cnt < n) {
      std::cout << "IMPOSSIBLE\n";
      continue;
    }
    std::vector<std::vector<int>> nwed(n);
    for (int u = 0; u < n; u++) {
      if (imp)
        break;
      for (auto v : ed[u]) {
        if (lnk[v] == u) {
          for (int i = 0; i < n; i++) {
            nwed[lnk[i]].push_back(i);
          }
          continue;
        }
        for (int i = 0; i < n; i++)
          if (lnk[i] == u)
            lnk[i] = -1;
        int tmp = lnk[v];
        lnk[v] = u;
        std::vector<bool> vis(n, 0);
        vis[v] = 1;
        if (!dfs(dfs, tmp, vis)) {
          imp = 1;
          break;
        }
        for (int i = 0; i < n; i++) {
          nwed[lnk[i]].push_back(i);
        }
      }
    }
    if (imp) {
      std::cout << "IMPOSSIBLE\n";
      continue;
    }
    std::cout << n * m + 1 << "\n";
    std::vector<int> ans(n * m);
    int cans = 0;
    auto fnd = [&](const auto &fnd, const int &u) -> void {
      while (nwed[u].size()) {
        int v = nwed[u].back();
        nwed[u].pop_back();
        fnd(fnd, v);
        ans[cans++] = u;
      }
    };
    fnd(fnd, 0);
    int st = 0;
    for (; ans[st] != 0; st++)
      ;
    for (int i = st; ~i; i--) {
      std::cout << ans[i] + 1 << " ";
    }
    for (int i = n * m - 1; i > st; i--) {
      std::cout << ans[i] + 1 << " ";
    }
    std::cout << "1\n";
  }
}

Details

answer.code:1:10: fatal error: _timeval.h: No such file or directory
    1 | #include <_timeval.h>
      |          ^~~~~~~~~~~~
compilation terminated.