Submission #73133507


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vvvl=vector<vector<vector<long long>>>;
using pl=pair<long long,long long>;
using vpl=vector<pair<long long,long long>>;
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(long long i=(long long)(a);i<(long long)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#include <atcoder/all>
using namespace atcoder;

long long modpow(long long a, long long n, long long mo){long long res=1;while(n>0){if(n&1){res=res*a%mo;}a=a*a%mo;n>>=1;}return res;}
long long Pow(long long a, long long n){long long res=1;while(n>0){if(n&1){res=res*a;}a=a*a;n>>=1;}return res;}

const ll MOD=998244353;
const ll INF=(1ll<<60);
struct edge{
  ll to;
  ll co;
};
int main(){
  ll T;
  cin>>T;
  rep(jfoda,T){
    ll N,M;
    cin>>N>>M;
    vl A(M),B(M),X(M);
    vector<vector<edge>> G(N);
    rep(i,M){
      cin>>A[i]>>B[i]>>X[i];
      A[i]--;B[i]--;
      G[A[i]].pb({B[i],X[i]});
      G[B[i]].pb({A[i],X[i]});
    }
    if(N%2==1){
      cout<<-1<<endl;
      continue;
    }
    queue<ll> q;
    vl s(N,-1);
    q.push(0);
    s[0]=0;
    while(!q.empty()){
      ll p=q.front();
      q.pop();
      for(auto e:G[p]){
        if(s[e.to]!=-1) continue;
        s[e.to]=(s[p] ^ e.co);
        q.push(e.to);
      }
    }
    ll mem=0;
    rep(i,N+1){
      mem=(mem^(i));
    }
    ll mee=0;
    rep(i,N){
      mem=(mem^s[i]);
    }
    cout<<(mem ^ mee)<<endl;
  }
}

Submission Info

Submission Time
Task B - Missing Number in Graph
User number_cat
Language C++23 (GCC 15.2.0)
Score 500
Code Size 1769 Byte
Status AC
Exec Time 144 ms
Memory 25312 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 26
Set Name Test Cases
Sample sample-01.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, sample-01.txt
Case Name Status Exec Time Memory
01-01.txt AC 73 ms 3712 KiB
01-02.txt AC 82 ms 3540 KiB
01-03.txt AC 91 ms 4012 KiB
01-04.txt AC 93 ms 4268 KiB
01-05.txt AC 93 ms 4312 KiB
01-06.txt AC 93 ms 4280 KiB
01-07.txt AC 95 ms 4904 KiB
01-08.txt AC 105 ms 6080 KiB
01-09.txt AC 99 ms 6052 KiB
02-01.txt AC 138 ms 24620 KiB
02-02.txt AC 130 ms 22992 KiB
02-03.txt AC 75 ms 18636 KiB
02-04.txt AC 75 ms 18636 KiB
02-05.txt AC 119 ms 25312 KiB
02-06.txt AC 120 ms 22112 KiB
02-07.txt AC 144 ms 24656 KiB
02-08.txt AC 132 ms 23132 KiB
02-09.txt AC 137 ms 24668 KiB
02-10.txt AC 126 ms 23108 KiB
03-01.txt AC 125 ms 21788 KiB
03-02.txt AC 84 ms 17168 KiB
03-03.txt AC 80 ms 16184 KiB
03-04.txt AC 84 ms 17280 KiB
03-05.txt AC 79 ms 16208 KiB
03-06.txt AC 83 ms 17336 KiB
sample-01.txt AC 1 ms 3628 KiB