QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129174#4635. Graph Operationnhuang685WA 1ms3528kbC++202.3kb2023-07-22 04:33:352023-07-22 04:33:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 04:33:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3528kb
  • [2023-07-22 04:33:35]
  • 提交

answer

/**
 * @file qoj4635F1.cpp
 * @author n685
 * @brief
 * @date 2023-07-21
 *
 *
 */
#include <bits/stdc++.h>

#ifdef LOCAL
std::ifstream cin;
std::ofstream cout;
using std::cerr;
#else
using std::cin;
using std::cout;
#define cerr                                                                   \
  if (false)                                                                   \
  std::cerr
#endif

struct Q {
  int a, b, c, d;
};
std::ostream &operator<<(std::ostream &out, const Q &q) {
  out << q.a + 1 << ' ' << q.b + 1 << ' ' << q.c + 1 << ' ' << q.d + 1;
  return out;
}

const int MX = 1000;

int main() {
#ifdef LOCAL
  cin.open("input.txt");
  cout.rdbuf()->pubsetbuf(0, 0);
  cout.open("output.txt");
#else
  cin.tie(nullptr)->sync_with_stdio(false);
#endif

  int n, m;
  cin >> n >> m;

  std::vector<std::bitset<MX>> g(n), h(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u][v] = 1;
    g[v][u] = 1;
  }
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    h[u][v] = 1;
    h[v][u] = 1;
  }

  for (int i = 0; i < n; ++i) {
    if (g[i].count() != h[i].count()) {
      cout << "-1\n";
      return 0;
    }
  }

  std::vector<Q> gg, hh;
  for (int i = 0; i < n; ++i) {
    auto gnh = g[i] & (~h[i]);
    auto hng = h[i] & (~g[i]);
    int v = (int)gnh._Find_first(), w = (int)hng._Find_first();
    while (v != MX && w != MX) {
      int t;
      if ((t = (int)((~g[v] & g[w])._Find_first())) != MX) {
        gg.push_back({i, v, w, t});
        g[i][v] = 0;
        g[v][i] = 0;

        g[i][w] = 1;
        g[w][i] = 1;

        g[t][w] = 0;
        g[w][t] = 0;

        g[t][v] = 1;
        g[v][t] = 1;
      } else {
        t = (int)(h[v] & ~h[w])._Find_first();
        hh.push_back({i, w, v, t});
        h[i][w] = 0;
        h[w][i] = 0;

        h[i][v] = 1;
        h[v][i] = 1;

        h[t][v] = 0;
        h[v][t] = 0;

        h[t][w] = 1;
        h[w][t] = 1;
      }

      gnh = g[i] & (~h[i]);
      hng = h[i] & (~g[i]);
      v = (int)gnh._Find_first(), w = (int)hng._Find_first();
    }
  }

  for (auto &a : gg)
    cout << a << '\n';
  for (auto &b : hh | std::views::reverse)
    cout << b << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3528kb

input:

4 2
1 2
3 4
1 3
2 4

output:

1 2 3 4

result:

wrong output format Unexpected end of file - int32 expected