QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#809651#9866. Extracting Weightsucup-team4479#WA 1ms3604kbC++232.8kb2024-12-11 16:33:412024-12-11 16:33:53

Judging History

你现在查看的是最新测评结果

  • [2024-12-11 16:33:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3604kb
  • [2024-12-11 16:33:41]
  • 提交

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
*/

Details

Tip: Click on the bar to expand more detailed information

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 "!"