QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#653767 | #6613. Bitwise Exclusive-OR Sequence | nahida_qaq | WA | 2ms | 9816kb | C++17 | 1.5kb | 2024-10-18 20:36:20 | 2024-10-18 20:36:29 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
using namespace std;
const int N=1e5+5,mod1=1e9+7,mod2=998244353;
typedef pair<int,int> pi;
int a[N][40];
int st[N][40];
int n,m;
vector<pi>g[100005];
int mp[N];
int dfs(int u,int x,int i)
{
mp[u]=1;
st[u][i]=1;
a[u][i]=x;
int ans=x;
for(auto [v,w]:g[u])
{
int y=(w>>i)&1;
if(st[v][i])
{
int z=(a[v][i])&1;
if(x^y!=z)return -1;
}
else
{
a[v][i]=x^y;
int xx=dfs(v,a[v][i],i);
if(xx==-1)return -1;
ans+=xx;
}
}
return ans;
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y,w;
cin>>x>>y>>w;
g[x].pb({y,w});
g[y].pb({x,w});
}
int ans=0;
for(int i=1;i<=n;i++)
{
if(mp[i])continue;
for(int j=0;j<=30;j++)
{
int ans1=dfs(i,0,j);
int ans2=dfs(i,1,j);
if(ans1==-1&&ans2==-1)
{
cout<<-1;
return ;
}
if(ans1==-1)ans+=(ans2<<j);
else if(ans2==-1)ans+=(ans1<<j);
else ans+=(min(ans1,ans2)<<j);
}
}
cout<<ans;
}
signed main()
{
io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9816kb
input:
3 2 1 2 1 2 3 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8356kb
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: 8296kb
input:
5 5 3 4 12 3 1 20 2 5 16 1 4 24 4 5 19
output:
82
result:
wrong answer 1st numbers differ - expected: '58', found: '82'