QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649119#6613. Bitwise Exclusive-OR Sequencenahida_qaqWA 1ms9940kbC++171.4kb2024-10-17 21:43:062024-10-17 21:43:06

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 21:43:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9940kb
  • [2024-10-17 21:43:06]
  • 提交

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'