QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#787992 | #6613. Bitwise Exclusive-OR Sequence | Loxilante | WA | 1ms | 11840kb | C++20 | 1.9kb | 2024-11-27 15:30:34 | 2024-11-27 15:30:38 |
Judging History
answer
#define F_C
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define int ll
using namespace std;
typedef long long ll;
template<typename tn = int> tn next(void) { tn k; cin>>k; return k; }
#ifndef LOCAL
#define D(...) 0
#endif
const int U = 5e5;
int fa[U], siz[U];
int find(int e)
{
if (fa[e] == e) return e;
return fa[e] = find(fa[e]);
}
void merge(int u, int v)
{
siz[find(u)] += siz[find(v)];
fa[find(v)] = find(u);
}
int head[U], nxt[U], to[U], val[U], tot;
void add(int x, int y, int z)
{
to[++tot] = y; val[tot] = z; nxt[tot] = head[x]; head[x] = tot;
}
signed main(void)
{
#ifdef LOCAL
// freopen("C:\\Users\\Loxil\\Desktop\\IN.txt", "r", stdin);
// freopen("C:\\Users\\Loxil\\Desktop\\OUT.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin>>n>>m;
rep(i, 0, m) { int u, v, w; cin>>u>>v>>w; add(u, v, w); }
int ans = 0;
rep(b, 0, 30)
{
hrp(i, 1, n) fa[i] = i, fa[i+n] = i+n, siz[i] = 1;
hrp(x, 1, n) for(int i = head[x]; i; i = nxt[i])
{
int y = to[i], z = val[i];
if ((z>>b)&1)
{
if (find(x) == find(y) || find(x+n) == find(y+n)) return cout<<-1<<endl, 0;
merge(x, y+n); merge(x+n, y);
}
else
{
if (find(x) == find(y+n) || find(x+n) == find(y)) return cout<<-1<<endl, 0;
merge(x, y); merge(x+n, y+n);
}
}
hrp(i, 1, n)
{
ans += min(siz[find(i)], siz[find(i+n)])*(1<<b);
siz[find(i)] = siz[find(i+n)] = 0;
}
}
cout<<ans<<endl;
return 0;
}
/*
4 2
1 2 3
2 3 6
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 11840kb
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: 11776kb
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: 1ms
memory: 11772kb
input:
5 5 3 4 12 3 1 20 2 5 16 1 4 24 4 5 19
output:
5368709054
result:
wrong answer 1st numbers differ - expected: '58', found: '5368709054'