Submission #66759824
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;#define rep(i, n) for (int i = 0; i < (int)(n); i++)using ll = long long;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int n, m;cin >> n >> m;vector<vector<pair<int, ll>>> g(n);rep(i, m) {int a, b;ll w;cin >> a >> b >> w;--a;--b;g[a].emplace_back(b, w);}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<pair<int, ll>>> g(n);
rep(i, m) {
int a, b;
ll w;
cin >> a >> b >> w;
--a;
--b;
g[a].emplace_back(b, w);
}
const ll INF = LLONG_MAX;
vector<ll> dist(n, INF);
vector<ll> basis(60, 0);
dist[0] = 0;
queue<int> que;
que.push(0);
while (!que.empty()) {
int u = que.front();
que.pop();
for (auto [v, w] : g[u]) {
if (dist[v] == INF) {
dist[v] = dist[u] ^ w;
que.push(v);
} else {
ll x = dist[u] ^ w ^ dist[v];
for (int bit = 59; bit >= 0; --bit) {
if (!(x >> bit & 1)) continue;
if (!basis[bit]) {
basis[bit] = x;
break;
}
x ^= basis[bit];
}
}
}
}
ll res = dist[n - 1];
if (res == INF) {
cout << -1 << "\n";
return 0;
}
for (int bit = 59; bit >= 0; --bit) {
res = min(res, res ^ basis[bit]);
}
cout << res << "\n";
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - XOR Shortest Walk |
| User | wisteriahuman |
| Language | C++ 23 (Clang 16.0.6) |
| Score | 0 |
| Code Size | 1440 Byte |
| Status | WA |
| Exec Time | 2 ms |
| Memory | 3676 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 | 3460 KiB |
| hand_02.txt | AC | 1 ms | 3524 KiB |
| hand_03.txt | AC | 1 ms | 3440 KiB |
| hand_04.txt | AC | 1 ms | 3656 KiB |
| hand_05.txt | AC | 1 ms | 3476 KiB |
| hand_06.txt | WA | 1 ms | 3524 KiB |
| hand_07.txt | WA | 2 ms | 3652 KiB |
| hand_08.txt | WA | 1 ms | 3520 KiB |
| random_01.txt | AC | 1 ms | 3408 KiB |
| random_02.txt | AC | 1 ms | 3492 KiB |
| random_03.txt | AC | 1 ms | 3476 KiB |
| random_04.txt | AC | 1 ms | 3500 KiB |
| random_05.txt | AC | 1 ms | 3472 KiB |
| random_06.txt | AC | 1 ms | 3532 KiB |
| random_07.txt | AC | 1 ms | 3584 KiB |
| random_08.txt | AC | 1 ms | 3552 KiB |
| random_09.txt | AC | 1 ms | 3480 KiB |
| random_10.txt | AC | 1 ms | 3580 KiB |
| random_11.txt | AC | 1 ms | 3504 KiB |
| random_12.txt | AC | 1 ms | 3488 KiB |
| random_13.txt | AC | 1 ms | 3396 KiB |
| random_14.txt | AC | 1 ms | 3676 KiB |
| random_15.txt | AC | 1 ms | 3596 KiB |
| random_16.txt | AC | 1 ms | 3552 KiB |
| random_17.txt | AC | 1 ms | 3536 KiB |
| random_18.txt | AC | 1 ms | 3572 KiB |
| random_19.txt | AC | 1 ms | 3576 KiB |
| random_20.txt | AC | 1 ms | 3600 KiB |
| random_21.txt | AC | 1 ms | 3476 KiB |
| random_22.txt | AC | 1 ms | 3512 KiB |
| sample_01.txt | AC | 1 ms | 3656 KiB |
| sample_02.txt | AC | 1 ms | 3584 KiB |
| sample_03.txt | AC | 1 ms | 3540 KiB |