QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#809651 | #9866. Extracting Weights | ucup-team4479# | WA | 1ms | 3604kb | C++23 | 2.8kb | 2024-12-11 16:33:41 | 2024-12-11 16:33:53 |
Judging History
answer
#include <bits/stdc++.h>
#define PII pair <int, int>
using namespace std;
const int N = 255;
vector <int> E[N];
bitset <N> vis[N], bit[N];
int val[N], n, ans[N];
bool a[N][N];
void print(bitset <N> &x) {
for (int i = 1; i <= n; ++i)
cout << x[i];
cout << endl;
}
bool insert(bitset <N> x) {
for (int i = n; i >= 2; --i) {
if (x[i])
if (bit[i].any()) x ^= bit[i];
else {
bit[i] = x;
return true;
}
}
return false;
}
void dfs(int u, int fa) {
vis[u] = vis[fa];
vis[u][u] = 1;
for (int v : E[u]) {
if (v == fa) continue;
dfs(v, u);
}
}
void Gauss() {
for (int i = 1; i < n; ++i) {
int k = 0;
for (int j = i; j < n; ++j)
if (a[j][i + 1]) {
k = j;
break;
}
for (int j = 1; j <= n; ++j)
swap(a[i][j], a[k][j]);
swap(val[i], val[k]);
for (int j = i + 1; j < n; ++j) {
if (!a[j][i + 1]) continue;
for (int k = 1; k <= n; ++k)
a[j][k] ^= a[i][k];
val[j] ^= val[i];
}
}
// for (int i = 1; i < n; ++i) {
// for (int j = 1; j <= n; ++j)
// cout << a[i][j] << " ";
// cout << val[i] << endl;
// }
for (int i = n - 1; i >= 1; --i) {
for (int j = i + 2; j <= n; ++j)
if (a[i][j]) val[i] ^= ans[j];
ans[i + 1] = val[i];
}
}
int main() {
// cin.tie(nullptr) -> ios::sync_with_stdio(false);
// cout.tie(0);
int k, u, v;
cin >> n >> k;
for (int i = 1; i < n; ++i) {
cin >> u >> v;
E[u].push_back(v);
E[v].push_back(u);
}
vector <PII> ques;
int now = 0;
for (int u = 1; u <= n; ++u) {
dfs(u, 0);
for (int v = 1; v <= n; ++v) {
if (vis[v].count() != k + 1) continue;
// cout << u << " " << v << " ";
// print(vis[v]);
if (insert(vis[v])) {
ques.push_back({u, v});
++now;
for (int i = 1; i <= n; ++i)
a[now][i] = vis[v][i];
}
}
}
if (now < n - 1) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
cout << "?";
for (auto [u, v] : ques) cout << " " << u << " " << v;
cout << endl;
for (int i = 1; i <= now; ++i) cin >> val[i];
// for (int i = 1; i < n; ++i) {
// for (int j = 1; j <= n; ++j)
// cout << a[i][j] << " ";
// cout << val[i] << endl;
// }
Gauss();
cout << "!";
for (int i = 2; i <= n; ++i) cout << " " << ans[i];
cout << endl;
return 0;
}
/*
4 1
1 2
2 3
2 4
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3604kb
input:
4 1 1 2 2 3 2 4 -1
output:
YES ? 1 2 2 3 2 4
result:
wrong answer Token "3" doesn't correspond to pattern "!"