跳到正文

题解

题解:P12826 「DLESS-2」XOR and Tree Construction

lcjKING约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月19日
篇幅
约 2 分钟
获赞
1
题目
P12826

版本

  1. v1当前

这道题嘛…真的太简单了

C++
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<vector<long long>> mat(n, vector<long long>(n));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                cin >> mat[i][j];
        vector<long long> a(n + 1);
        for (int i = 1; i <= n; i++)
            a[i] = mat[i - 1][i - 1];
        vector<pair<int, int>> edges;
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                long long b_ij = mat[i - 1][j - 1];
                long long xor_val = a[i] ^ a[j];
                if (b_ij == xor_val)
                    edges.push_back({i, j});
            }
        }
        for (int i = 1; i <= n; i++)
            cout << a[i] << " ";
        cout << "\n";
        for (auto &e : edges)
            cout << e.first << " " << e.second << "\n";
    }
    return 0;
}
原文