Submission #66750699
Source Code Expand
Copy
#include <iostream>#include <vector>#include <algorithm>#include <queue>using namespace std;struct Xorbasis{static constexpr int B = 10;int a[B] = {};void add(int x){for(int i = B - 1; i >= 0; i--){if(x & (1 << i)){if(!a[i]){a[i] = x;return;}}}}
#include <iostream> #include <vector> #include <algorithm> #include <queue> using namespace std; struct Xorbasis { static constexpr int B = 10; int a[B] = {}; void add(int x){ for(int i = B - 1; i >= 0; i--){ if(x & (1 << i)) { if(!a[i]) { a[i] = x; return; } } } } int minimize(int x) const { for(int i = B - 1; i>=0; --i){ if(a[i] && (x ^ a[i]) < x) { x ^= a[i]; } } return x; } }; int main(){ int n,m; cin >> n >> m; struct Edge{int u,v,w;}; vector<Edge> edges(m); vector<vector<pair<int,int>>> g(n+1); for(int i =0;i<m;i++){ int a,b,w; cin >> a >> b >> w; edges[i] = {a, b, w}; g[a].push_back({b, w}); } vector<int> dist(n+1,-1); queue<int> q; dist[1] = 0; q.push(1); while(!q.empty()) { int u = q.front(); q.pop(); for(auto [v,w]:g[u]) { if(dist[v] == -1) { dist[v] = dist[u]^w; q.push(v); } } } if(dist[n] == -1) { cout << -1 << endl; return 0; } Xorbasis basis; for(auto [u,v,w]:edges) { if(!dist[u]!= -1 && dist[v] != -1) { basis.add(dist[u] ^ dist[v] ^ w); } } cout << basis.minimize(dist[n]) << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - XOR Shortest Walk |
User | kotakun2724 |
Language | C++ 20 (gcc 12.2) |
Score | 0 |
Code Size | 1618 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 3720 KiB |
Compile Error
Main.cpp: In function ‘int main()’: Main.cpp:73:20: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses] 73 | if(!dist[u]!= -1 && dist[v] != -1) | ^~ Main.cpp:73:12: note: add parentheses around left hand side expression to silence this warning 73 | if(!dist[u]!= -1 && dist[v] != -1) Main.cpp:73:20: warning: comparison of constant ‘-1’ with boolean expression is always true [-Wbool-compare] 73 | if(!dist[u]!= -1 && dist[v] != -1) | ~~~~~~~~^~~~~
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 | 3528 KiB |
hand_02.txt | AC | 1 ms | 3676 KiB |
hand_03.txt | AC | 1 ms | 3656 KiB |
hand_04.txt | AC | 1 ms | 3536 KiB |
hand_05.txt | WA | 1 ms | 3720 KiB |
hand_06.txt | WA | 1 ms | 3588 KiB |
hand_07.txt | WA | 1 ms | 3540 KiB |
hand_08.txt | WA | 1 ms | 3520 KiB |
random_01.txt | AC | 1 ms | 3592 KiB |
random_02.txt | AC | 1 ms | 3568 KiB |
random_03.txt | AC | 1 ms | 3524 KiB |
random_04.txt | AC | 1 ms | 3704 KiB |
random_05.txt | AC | 1 ms | 3580 KiB |
random_06.txt | AC | 1 ms | 3596 KiB |
random_07.txt | AC | 1 ms | 3492 KiB |
random_08.txt | AC | 1 ms | 3544 KiB |
random_09.txt | AC | 1 ms | 3524 KiB |
random_10.txt | AC | 1 ms | 3648 KiB |
random_11.txt | AC | 1 ms | 3656 KiB |
random_12.txt | AC | 1 ms | 3576 KiB |
random_13.txt | WA | 1 ms | 3536 KiB |
random_14.txt | WA | 1 ms | 3608 KiB |
random_15.txt | WA | 1 ms | 3596 KiB |
random_16.txt | AC | 1 ms | 3508 KiB |
random_17.txt | AC | 1 ms | 3580 KiB |
random_18.txt | AC | 2 ms | 3516 KiB |
random_19.txt | AC | 1 ms | 3556 KiB |
random_20.txt | AC | 1 ms | 3580 KiB |
random_21.txt | AC | 1 ms | 3588 KiB |
random_22.txt | AC | 1 ms | 3572 KiB |
sample_01.txt | AC | 1 ms | 3524 KiB |
sample_02.txt | AC | 1 ms | 3588 KiB |
sample_03.txt | AC | 1 ms | 3612 KiB |