QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#675469 | #6613. Bitwise Exclusive-OR Sequence | ivyoruska# | WA | 0ms | 3648kb | C++20 | 1.8kb | 2024-10-25 18:38:23 | 2024-10-25 18:38:23 |
Judging History
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 num1;
int num2;
bool dfs(int x) {
if(col[x]==0)num1++;
else num2++;
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) {
num1 = 0;
num2 = 0;
col[i] = 0;
if (dfs(i)) {
res += 1LL * min(num1,num2) * (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: 3564kb
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: 3648kb
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: 3616kb
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'