Submission #66757143
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;#define rep(i,n) for(int i=0;i<(n);i++)#define all(a) a.begin(),a.end()#define rall(a) a.rbegin(),a.rend()#define YES cout<<"Yes"<<endl#define NO cout<<"No"<<endlusing ll=long long;using pi=pair<int,int>;const int di[]={+1,-1,+0,+0};const int dj[]={+0,+0,+1,-1};const int INF=1e9;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n, m;cin >> n >> m;vector<vector<pi>> G(n);rep(i, m) {int a, b, w;cin >> a >> b >> w;
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
using ll=long long;
using pi=pair<int,int>;
const int di[]={+1,-1,+0,+0};
const int dj[]={+0,+0,+1,-1};
const int INF=1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<pi>> G(n);
rep(i, m) {
int a, b, w;
cin >> a >> b >> w;
a--; b--;
G[a].push_back({w, b});
}
queue<int> que;
que.push(0);
vector<int> dist(n, -1);
dist[0]=0;
vector<int> basis(11);
auto inbit=[&](ll x) {
for(int bit=10; bit>=0; bit--) {
if(!(x&(1LL<<bit))) continue;
if(basis[bit]==0) {
basis[bit]=x;
break;
}
x^=basis[bit];
}
};
while(!que.empty()) {
int v=que.front();
que.pop();
for(auto [nw, nv]:G[v]) {
if(dist[nv]==-1) {
dist[nv]=dist[v]^nw;
que.push(nv);
} else {
int cycle=dist[v]^nw^dist[nv];
if(cycle) inbit(cycle);
}
}
}
if(dist.back()==-1) {
cout << -1 << endl;
return 0;
}
int ans=dist.back();
for(int b=10; b>=0; b--) {
if((ans^basis[b])<ans) ans^=basis[b];
}
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | dmainf |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1580 Byte |
| Status | WA |
| Exec Time | 1 ms |
| Memory | 3664 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 400 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01.txt | AC | 1 ms | 3464 KiB |
| hand_02.txt | AC | 1 ms | 3464 KiB |
| hand_03.txt | AC | 1 ms | 3468 KiB |
| hand_04.txt | AC | 1 ms | 3604 KiB |
| hand_05.txt | AC | 1 ms | 3484 KiB |
| hand_06.txt | WA | 1 ms | 3504 KiB |
| hand_07.txt | WA | 1 ms | 3576 KiB |
| hand_08.txt | WA | 1 ms | 3464 KiB |
| random_01.txt | AC | 1 ms | 3464 KiB |
| random_02.txt | AC | 1 ms | 3480 KiB |
| random_03.txt | AC | 1 ms | 3476 KiB |
| random_04.txt | AC | 1 ms | 3504 KiB |
| random_05.txt | AC | 1 ms | 3472 KiB |
| random_06.txt | AC | 1 ms | 3616 KiB |
| random_07.txt | AC | 1 ms | 3400 KiB |
| random_08.txt | AC | 1 ms | 3516 KiB |
| random_09.txt | AC | 1 ms | 3472 KiB |
| random_10.txt | AC | 1 ms | 3456 KiB |
| random_11.txt | AC | 1 ms | 3416 KiB |
| random_12.txt | AC | 1 ms | 3516 KiB |
| random_13.txt | AC | 1 ms | 3488 KiB |
| random_14.txt | AC | 1 ms | 3496 KiB |
| random_15.txt | AC | 1 ms | 3556 KiB |
| random_16.txt | AC | 1 ms | 3448 KiB |
| random_17.txt | AC | 1 ms | 3664 KiB |
| random_18.txt | AC | 1 ms | 3596 KiB |
| random_19.txt | AC | 1 ms | 3528 KiB |
| random_20.txt | AC | 1 ms | 3528 KiB |
| random_21.txt | AC | 1 ms | 3588 KiB |
| random_22.txt | AC | 1 ms | 3388 KiB |
| sample_01.txt | AC | 1 ms | 3488 KiB |
| sample_02.txt | AC | 1 ms | 3420 KiB |
| sample_03.txt | AC | 1 ms | 3424 KiB |