QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#123673 | #4635. Graph Operation | HaccerKat | WA | 1ms | 3460kb | C++20 | 5.6kb | 2023-07-13 11:17:50 | 2023-07-13 11:17:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T>
int SIZE(T (&t)){
return t.size();
}
template<typename T, size_t N>
int SIZE(T (&t)[N]){
return N;
}
string to_string(char t){
return "'" + string({t}) + "'";
}
string to_string(bool t){
return t ? "true" : "false";
}
string to_string(const string &t, int x1=0, int x2=1e9){
string ret = "";
for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){
ret += t[i];
}
return '"' + ret + '"';
}
string to_string(const char* t){
string ret(t);
return to_string(ret);
}
template<size_t N>
string to_string(const bitset<N> &t, int x1=0, int x2=1e9){
string ret = "";
for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){
ret += t[i] + '0';
}
return to_string(ret);
}
template<typename T, typename... Coords>
string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C);
template<typename T, typename S>
string to_string(const pair<T, S> &t){
return "(" + to_string(t.first) + ", " + to_string(t.second) + ")";
}
template<typename T, typename... Coords>
string to_string(const T (&t), int x1, int x2, Coords... C){
string ret = "[";
x1 = min(x1, SIZE(t));
auto e = begin(t);
advance(e,x1);
for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){
ret += to_string(*e, C...) + (i != _i ? ", " : "");
e = next(e);
}
return ret + "]";
}
template<int Index, typename... Ts>
struct print_tuple{
string operator() (const tuple<Ts...>& t) {
string ret = print_tuple<Index - 1, Ts...>{}(t);
ret += (Index ? ", " : "");
return ret + to_string(get<Index>(t));
}
};
template<typename... Ts>
struct print_tuple<0, Ts...> {
string operator() (const tuple<Ts...>& t) {
return to_string(get<0>(t));
}
};
template<typename... Ts>
string to_string(const tuple<Ts...>& t) {
const auto Size = tuple_size<tuple<Ts...>>::value;
return print_tuple<Size - 1, Ts...>{}(t);
}
void dbgr(){;}
template<typename Heads, typename... Tails>
void dbgr(Heads H, Tails... T){
cout << to_string(H) << " | ";
dbgr(T...);
}
void dbgs(){;}
template<typename Heads, typename... Tails>
void dbgs(Heads H, Tails... T){
cout << H << " ";
dbgs(T...);
}
/*
formatted functions:
*/
/*
consider __VA_ARGS__ as a whole:
dbgv() prints values only
dbg() prints name and values
*/
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
//#define dbg(...)
/*
consider __VA_ARGS__ as a sequence of arguments:
dbgr() prints values only
dbgm() prints names and values
*/
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
// using u128 = __uint128_t;
// using i128 = __int128;
const int mod = 1000000007;
const int N = 5;
const int LOG = 20;
const int inf = 1e9;
const double eps = 1e-11;
int n, m, k, qq;
bitset<N> adj1[N], adj2[N];
int deg[N];
void solve() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
adj1[u][v] = adj1[v][u] = 1;
deg[u]++, deg[v]++;
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
adj2[u][v] = adj2[v][u] = 1;
deg[u]--, deg[v]--;
}
for (int i = 1; i <= n; i++) {
if (deg[i] != 0) {
cout << "-1\n";
return;
}
}
vector<array<int, 4>> opG, opH;
for (int u = 1; u <= n - 3; u++) {
while (true) {
bitset<N> bs = (adj1[u] | adj2[u]) ^ adj2[u];
if (bs.none()) break;
int v = bs._Find_first();
bs = (adj2[u] | adj1[u]) ^ adj1[u];
int w = bs._Find_first();
bs = (adj1[w] | adj1[v]) ^ adj1[v];
bool b = 0;
if (bs.none()) b = 1, bs = (adj2[v] | adj2[w]) ^ adj2[w];
int t = bs._Find_first();
if (b) {
opH.push_back({u, w, v, t});
adj2[u][w] = adj2[w][u] = adj2[v][t] = adj2[t][v] = 0;
adj2[u][v] = adj2[v][u] = adj2[w][t] = adj2[t][w] = 1;
}
else {
opG.push_back({u, v, w, t});
adj1[u][v] = adj1[v][u] = adj1[w][t] = adj1[t][w] = 0;
adj1[u][w] = adj1[w][u] = adj1[v][t] = adj1[t][v] = 1;
}
}
}
cout << opG.size() + opH.size() << "\n";
for (auto [u, v, w, x] : opG) {
cout << u << " " << v << " " << w << " " << x << "\n";
}
reverse(opH.begin(), opH.end());
for (auto [u, v, w, x] : opH) {
cout << u << " " << v << " " << w << " " << x << "\n";
}
}
int32_t main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
input:
4 2 1 2 3 4 1 3 2 4
output:
1 1 2 3 4
result:
ok n=4
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3460kb
input:
6 12 1 2 3 5 4 6 1 4 1 5 1 6 2 3 2 5 2 6 3 4 3 6 4 5 1 3 2 4 5 6 1 4 1 5 1 6 2 3 2 5 2 6 3 4 3 6 4 5
output:
-1
result:
wrong answer Wrong Answer!