QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#675413#6613. Bitwise Exclusive-OR Sequenceivyoruska#WA 0ms3632kbC++201.7kb2024-10-25 18:31:552024-10-25 18:31:55

Judging History

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

  • [2024-10-25 18:31:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2024-10-25 18:31:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
i64 res;
struct Bipartite_graph {
    int n;
    vector<vector<int> > gra;
    vector<int> col;
    int w;

    void init(int x) {
        n = x;
        gra.resize(n + 1);
        col.resize(n + 1);
    }

    void add_edge(int u, int v) {
        gra[u].emplace_back(v);
        gra[v].emplace_back(u);
    }
    int nums;

    bool dfs(int x) {
        nums++;
        for (int& y : gra[x]) {
            if (col[y] == -1) {
                col[y] = col[x] ^ 1;
                if (!dfs(y))return false;
            }
            else if (col[y] == col[x])
                return false;
        }
        return true;
    }


    bool work() {
        for (int i = 1; i <= n; i++)col[i] = -1;
        for (int i = 1; i <= n; i++) {
            if (col[i] == -1) {
                nums = 0;
                col[i] = 0;
                if (dfs(i)) {
                    res += 1LL * (nums / 2) * (1 << w);
                }
                else return false;
            }
        }
        return true;
    }
}gra[40];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i <= 30; i++) {
        gra[i].init(n);
        gra[i].w = i;
    }


    for (int i = 0; i < m; i++) {
        int u, v, w; cin >> u >> v >> w;
        for (int i = 30; i >= 0; i--) {
            if (w & (1 << i)) {
                gra[i].add_edge(u, v);
            }
        }
    }

    for (int i = 30; i >= 0; i--) {
        if (!gra[i].work()) {
            cout << -1 << '\n';
            return 0;
        }
    }

    cout << res;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

3 2
1 2 1
2 3 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

3 3
1 2 1
2 3 1
1 3 1

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3632kb

input:

5 5
3 4 12
3 1 20
2 5 16
1 4 24
4 5 19

output:

47

result:

wrong answer 1st numbers differ - expected: '58', found: '47'