QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153924 | #141. 8 染色 | nhuang685 | 0 | 22ms | 19020kb | C++14 | 3.5kb | 2023-08-31 10:47:40 | 2023-08-31 10:47:40 |
Judging History
Alice
#include "Alice.h"
namespace {
int sample_variable = 0;
void sample_function() {}
} // namespace
std::vector<int> Alice(int N, int M, std::vector<int> U, std::vector<int> V,
std::vector<int> C) {
std::vector<int> deg(N);
for (int i = 0; i < M; ++i) {
deg[U[i]]++;
deg[V[i]]++;
}
std::vector<int> &ans = V;
ans.resize(0);
for (int i = 0; i < N; ++i) {
if (deg[i] >= 8) {
ans.push_back(C[i] >= 4);
ans.push_back((C[i] / 2) % 2 == 0);
}
}
return ans;
}
Bob
#include "Bob.h"
#include <queue>
namespace {
int sample_variable = 0;
void sample_function() {}
} // namespace
std::vector<int> Bob(int N, int M, std::vector<int> U, std::vector<int> V,
std::vector<int> X) {
std::vector<std::vector<int>> adj(N);
for (int i = 0; i < M; ++i) {
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
std::vector<int> &C = V;
{
std::vector<int> ind(N, -1);
{
int cnt = 0;
for (int i = 0; i < N; ++i) {
if ((int)adj[i].size() >= 8) {
ind[i] = cnt;
cnt++;
adj[i].clear();
}
}
}
std::vector<std::vector<int>> bp(N);
// for (int i = 0; i < N; ++i) {
// if (ind[i] == -1)
// continue;
// for (int j : adj[i]) {
// if (ind[j] == -1)
// continue;
// if (X[2 * ind[i]] != X[2 * ind[j]] ||
// X[2 * ind[i] + 1] != X[2 * ind[j] + 1]) {
// continue;
// }
// bp[i].push_back(j);
// }
// }
for (int i = 0; i < M; ++i) {
if (ind[U[i]] == -1 || ind[V[i]] == -1)
continue;
if (X[2 * ind[U[i]]] != X[2 * ind[V[i]]])
continue;
if (X[2 * ind[U[i]] + 1] != X[2 * ind[V[i]]] + 1)
continue;
bp[U[i]].push_back(V[i]);
bp[V[i]].push_back(U[i]);
}
U.clear();
V.clear();
std::vector<bool> vis(N);
C.assign(N, -1);
std::vector<int> &q = U;
q.clear();
q.reserve(N);
int ii = 0;
for (int s = 0; s < N; ++s) {
if (ind[s] != -1 && !vis[s]) {
vis[s] = true;
// std::queue<int> q;
// q.push(s);
q.push_back(s);
int b = X[2 * ind[s]] * 4 + X[2 * ind[s] + 1] * 2;
C[s] = b;
// while (!q.empty()) {
while (ii < q.size()) {
// int node = q.front();
// q.pop();
int node = q[ii++];
for (int i : bp[node]) {
if (vis[i])
continue;
vis[i] = true;
C[i] = !(C[node] - b) + b;
// q.push(i);
q.push_back(i);
}
}
}
}
// int b;
// auto dfs = [&](auto &self, int node) -> void {
// for (int i : bp[node]) {
// if (vis[i])
// continue;
// vis[i] = true;
// C[i] = !(C[node] - b) + b;
// self(self, i);
// }
// };
// for (int s = 0; s < N; ++s) {
// if (ind[s] != -1 && !vis[s]) {
// vis[s] = true;
// b = X[2 * ind[s]] * 4 + X[2 * ind[s] + 1] * 2;
// C[s] = b;
// dfs(dfs, s);
// }
// }
}
for (int i = 0; i < N; ++i) {
if (C[i] == -1) {
for (int k = 0; k < 8; ++k) {
bool g = true;
for (int j : adj[i]) {
if (C[j] == k) {
g = false;
break;
}
}
if (g) {
C[i] = k;
break;
}
}
}
}
return C;
}
详细
Test #1:
score: 0
Wrong Answer
time: 22ms
memory: 19020kb
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 +000101101100011101010000000101001101100111011010011100010001110000010000100101111010001010000010010011111111000110111001100110110000011100111000000000001000000100111110011011100010011111010100110101000010011000000011000110011110001011111110100101101101101100000011010110111011011100110110101...
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 0 1 1 4 6 1 1 6 1 1 1 0 1 1 1 1 6 1 4 1 6 1 4 4 1 6 0 1 0 1 6 0 1 1 1 0 4 1 0 6 4 4 1 4 4 1 1 4 0 0 6 6 6 6 1 1 4 6 4 1 4 1 4 6 0 1 1 6 1 6 4 1 0 1 1 0 4 1 1 1 0 6 6 4 1 4 6 4 1 4 1 6 6 1 1 0 6 0 1 1 1 4 1 4 0 1 0 6 1 1 4 1 6 4 1 4 6 6 6 4 4 1 1 4 6 1 4 6 0 1 0 6 1 1 4 6 4 6 1 6 1 6 1 4 4 4 ...
result:
wrong answer the color of the vertex 5247 and 482 is the same