QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#395943 | #141. 8 染色 | hos_lyric | 0 | 0ms | 0kb | C++14 | 5.8kb | 2024-04-22 07:00:38 | 2024-04-22 07:00:39 |
Alice
#include "Alice.h"
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
namespace {
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// remove deg < 8
pair<vector<int>, vector<int>> removeEasy(int N, int M, const vector<int> &U, const vector<int> &V) {
vector<vector<int>> graph(N);
for (int i = 0; i < M; ++i) {
graph[U[i]].push_back(V[i]);
graph[V[i]].push_back(U[i]);
}
vector<int> deg(N);
vector<int> us;
for (int u = 0; u < N; ++u) {
deg[u] = graph[u].size();
if (deg[u] < 8) {
us.push_back(u);
}
}
for (int j = 0; j < (int)us.size(); ++j) {
const int u = us[j];
for (const int v : graph[u]) {
if (deg[v]-- == 8) {
us.push_back(v);
}
}
}
vector<int> del(N, 0);
for (const int u : us) del[u] = 1;
vector<int> vs;
for (int v = 0; v < N; ++v) if (!del[v]) vs.push_back(v);
return make_pair(us, vs);
}
} // namespace
std::vector <int> Alice(int N, int M, std::vector <int> U, std::vector <int> V, std::vector <int> C) {
const auto res = removeEasy(N, M, U, V);
// cerr<<"res = "<<res<<endl;
/*
remaining graph
deg(v) >= 8
==> |vs| <= (1/4) M
*/
vector<int> X;
for (const int v : res.second) {
X.push_back(C[v] >> 1 & 1);
X.push_back(C[v] >> 2 & 1);
}
return X;
}
Bob
#include "Bob.h"
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
namespace {
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
vector<int> uf;
int root(int u) {
return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return false;
if (uf[u] > uf[v]) swap(u, v);
uf[u] += uf[v];
uf[v] = u;
return true;
}
// remove deg < 8
pair<vector<int>, vector<int>> removeEasy(int N, int M, const vector<int> &U, const vector<int> &V) {
vector<vector<int>> graph(N);
for (int i = 0; i < M; ++i) {
graph[U[i]].push_back(V[i]);
graph[V[i]].push_back(U[i]);
}
vector<int> deg(N);
vector<int> us;
for (int u = 0; u < N; ++u) {
deg[u] = graph[u].size();
if (deg[u] < 8) {
us.push_back(u);
}
}
for (int j = 0; j < (int)us.size(); ++j) {
const int u = us[j];
for (const int v : graph[u]) {
if (deg[v]-- == 8) {
us.push_back(v);
}
}
}
vector<int> del(N, 0);
for (const int u : us) del[u] = 1;
vector<int> vs;
for (int v = 0; v < N; ++v) if (!del[v]) vs.push_back(v);
return make_pair(us, vs);
}
} // namespace
std::vector <int> Bob(int N, int M, std::vector <int> U, std::vector <int> V, std::vector <int> X) {
const auto res = removeEasy(N, M, U, V);
const auto &us = res.first, &vs = res.second;
vector<int> C(N, -1);
for (const int v : vs) C[v] = -2;
vector<int> uf(N << 1, -1);
for (int i = 0; i < M; ++i) if (C[U[i]] == -2 && C[V[i]] == -2) {
connect(U[i] << 1, V[i] << 1 | 1);
connect(V[i] << 1, U[i] << 1 | 1);
}
vector<int> colors(N << 1, -1);
{
int pos = 0;
for (const int v : vs) {
const int r = root(v << 1);
if (!~colors[r]) {
colors[r] = 0;
colors[root(r ^ 1)] = 1;
}
C[v] = colors[r];
C[v] |= X[pos++] << 1;
C[v] |= X[pos++] << 2;
}
}
vector<vector<int>> graph(N);
for (int i = 0; i < M; ++i) {
graph[U[i]].push_back(V[i]);
graph[V[i]].push_back(U[i]);
}
for (int j = (int)us.size(); --j >= 0; ) {
const int u = us[j];
int app = 0;
for (const int v : graph[u]) if (~C[v]) app |= 1 << C[v];
C[u] = __builtin_ctz(~app);
}
return C;
}
詳細信息
Test #1:
score: 0
Stage 2: Program Bob Runtime Error
input:
10000 500000 5247 482 4774 3796 5245 9386 8794 2818 1911 3240 6925 6008 6313 1737 8668 4913 7892 5444 6740 2271 2100 53 8527 9605 4009 4765 5293 2683 6552 1326 8877 9929 402 9849 8664 6893 1998 7305 155 9477 9753 8036 448 5438 8535 3111 9493 406 7694 2030 5745 6890 5519 3106 8979 5098 9948 2453 5601...
output:
Success +100000110110000100001010100000100100110001001111000110001000011010001010110000011111101111101011001001010101100011011100110011011010000110011110101010101110100010010111001101111011000101000010010000101011001110101001100011000111101101010111110000110100110110101001000011011101000110010011111...
input:
10000 500000 5247 482 4774 3796 5245 9386 8794 2818 1911 3240 6925 6008 6313 1737 8668 4913 7892 5444 6740 2271 2100 53 8527 9605 4009 4765 5293 2683 6552 1326 8877 9929 402 9849 8664 6893 1998 7305 155 9477 9753 8036 448 5438 8535 3111 9493 406 7694 2030 5745 6890 5519 3106 8979 5098 9948 2453 5601...
output:
Unauthorized output