QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#649119 | #6613. Bitwise Exclusive-OR Sequence | nahida_qaq | WA | 1ms | 9940kb | C++17 | 1.4kb | 2024-10-17 21:43:06 | 2024-10-17 21:43:06 |
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=1e6+5,mod1=1e9+7,mod2=998244353;
typedef pair<int,int> pi;
int a[N];
int st[N][40];
int n,m;
vector<pi>g[100005];
int dfs(int u,int x,int i)
{
st[u][i]=1;
int ans=x;
if(g[u].size()==1)return 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]=x^y;
int xx=dfs(v,a[v],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(st[i][0])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);
if(ans2==-1)ans+=(ans1<<j);
}
}
cout<<ans;
}
signed main()
{
io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6428kb
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: 9532kb
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: 9940kb
input:
5 5 3 4 12 3 1 20 2 5 16 1 4 24 4 5 19
output:
-1
result:
wrong answer 1st numbers differ - expected: '58', found: '-1'