QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129174 | #4635. Graph Operation | nhuang685 | WA | 1ms | 3528kb | C++20 | 2.3kb | 2023-07-22 04:33:35 | 2023-07-22 04:33:37 |
Judging History
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';
}
詳細信息
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