Submission #66774680
Source Code Expand
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> adj(n + 1);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w}); // For undirected graphs
}
// `dis[node]` = min XOR to reach `node`
vector<int> dis(n + 1, -1); // -1 means unvisited
queue<pair<int, int>> q; // {current_xor, node}
dis[1] = 0;
q.push({0, 1});
while (!q.empty()) {
auto current_xor = q.front().first;
int u = q.front().second;
q.pop();
for (auto child : adj[u]) {
int v = child.first;
int w = child.second;
int new_xor = current_xor ^ w;
if (dis[v] == -1 || new_xor < dis[v]) { // If unvisited or better XOR found
dis[v] = new_xor;
q.push({new_xor, v});
}
}
}
cout << dis[n] << endl; // -1 if no path exists
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | Sarthak_Borse |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1099 Byte |
| Status | WA |
| Exec Time | 2 ms |
| Memory | 3680 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 | 3484 KiB |
| hand_02.txt | AC | 1 ms | 3492 KiB |
| hand_03.txt | WA | 1 ms | 3476 KiB |
| hand_04.txt | AC | 1 ms | 3492 KiB |
| hand_05.txt | AC | 1 ms | 3584 KiB |
| hand_06.txt | WA | 1 ms | 3540 KiB |
| hand_07.txt | AC | 1 ms | 3524 KiB |
| hand_08.txt | AC | 1 ms | 3608 KiB |
| random_01.txt | AC | 1 ms | 3680 KiB |
| random_02.txt | AC | 2 ms | 3524 KiB |
| random_03.txt | AC | 1 ms | 3488 KiB |
| random_04.txt | AC | 1 ms | 3512 KiB |
| random_05.txt | AC | 1 ms | 3544 KiB |
| random_06.txt | AC | 1 ms | 3496 KiB |
| random_07.txt | AC | 1 ms | 3620 KiB |
| random_08.txt | AC | 1 ms | 3524 KiB |
| random_09.txt | AC | 1 ms | 3480 KiB |
| random_10.txt | AC | 2 ms | 3484 KiB |
| random_11.txt | AC | 1 ms | 3476 KiB |
| random_12.txt | AC | 2 ms | 3460 KiB |
| random_13.txt | WA | 1 ms | 3636 KiB |
| random_14.txt | WA | 1 ms | 3640 KiB |
| random_15.txt | WA | 1 ms | 3512 KiB |
| random_16.txt | AC | 1 ms | 3628 KiB |
| random_17.txt | AC | 2 ms | 3568 KiB |
| random_18.txt | AC | 2 ms | 3568 KiB |
| random_19.txt | AC | 2 ms | 3632 KiB |
| random_20.txt | AC | 2 ms | 3536 KiB |
| random_21.txt | WA | 2 ms | 3556 KiB |
| random_22.txt | WA | 2 ms | 3492 KiB |
| sample_01.txt | AC | 1 ms | 3476 KiB |
| sample_02.txt | AC | 1 ms | 3476 KiB |
| sample_03.txt | AC | 1 ms | 3500 KiB |