QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704174 | #6613. Bitwise Exclusive-OR Sequence | hansue# | Compile Error | / | / | C++20 | 2.0kb | 2024-11-02 19:27:32 | 2024-11-02 19:27:33 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long LL;
const int N = 1e5;
const int M = 2e5;
const int L = 30;
int n, m;
struct Edge{
int to, nxt, w;
}e[M * 2 + 3];
int etop, h[N + 3];
void adde(int u, int v, int w){
etop++;
e[etop].to = v;
e[etop].nxt = h[u];
e[etop].w = w;
h[u] = etop;
}
bool vis[N + 3];
bool colli;
int s[N + 3]; //presum xor of node i
int c[L + 3]; //count of s[]' bin digit being 1
int tot; //count of connecting block
LL ans;
void dfs(int u, int fr){
for(int tmp = h[u], v, news; tmp != -1; tmp = e[tmp].nxt){
v = e[tmp].to;
if(v == fr)
continue;
news = s[u] ^ e[tmp].w;
if(vis[v]){
if(s[v] != news)
colli = true;
return ;
}
else {
vis[v] = true;
s[v] = news;
tot++;
for(int i = 0; i < L; i++)
if((s[v] >> i) & 1)
c[i]++;
dfs(v, u);
if(colli)
return ;
}
}
}
int main(){
scanf("%d%d", &n, &m);
etop = 0;
memset(h, -1, sizeof h);
for(int i = 1, u, v, w; i <= m; i++){
scanf("%d%d%d", &u, &v, &w);
adde(u, v, w);
adde(v, u, w);
}
memset(vis, 0, sizeof vis);
colli = false;
ans = 0;
for(int i = 1; i <= n && !colli; i++)
if(!vis[i]){
vis[i] = true;
s[i] = 0;
memset(c, 0, sizeof c);
tot = 1;
dfs(i, 0);
if(colli)
return ;
for(int j = 0, t = 1; j < L; j++, t <<= 1){
ans += (LL)min(c[j], tot - c[j]) * t;
}
}
if(colli){
printf("-1\n");
return 0;
}
printf("%lld", ans);
return 0;
}
Details
answer.code: In function ‘int main()’: answer.code:89:17: error: return-statement with no value, in function returning ‘int’ [-fpermissive] 89 | return ; | ^~~~~~ answer.code:67:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 67 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ answer.code:72:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 72 | scanf("%d%d%d", &u, &v, &w); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~