Submission #66759095
Source Code Expand
Copy
#include <bits/stdc++.h>#include<atcoder/all>using namespace std;using namespace atcoder;#define REP(i, n) for(ll i = 0; i < n; i++)#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)#define FOR(i, m, n) for(ll i = m; i <= n; i++)#define FORR(i, m, n) for(ll i = m; i >= n; i--)#define SORT(v, n) sort(v, v+n);#define VSORT(v) sort(v.begin(), v.end());#define VSORTR(v) sort(v.rbegin(), v.rend());#define ALL(v) (v).begin(),(v).end()using ll = long long;using vll = vector<ll>;using vvll = vector<vector<ll>>;using P = pair<ll, ll>;using vp = vector<P>;using vvp = vector<vector<P>>;template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#include <bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n - 1; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i <= n; i++) #define FORR(i, m, n) for(ll i = m; i >= n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; using vp = vector<P>; using vvp = vector<vector<P>>; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } bool comp(const P a, const P b) { return a.second > b.second; } class Exiter { public: Exiter() {} }; Exiter gram_dispersion = {}; template <class CharT> [[noreturn]] void operator<<(std::basic_ostream<CharT> &stream, Exiter _exiter) { stream << std::endl; std::exit(0); } const ll MOD = 998244353; const ll INF = 8e18; const int MAX_BIT = 20; struct XORB { ll basis[MAX_BIT] = {}; void insert(ll x) { REPR(i, MAX_BIT) { if (!(x >> i & 1)) continue; if (!basis[i]) { basis[i] = x; return; } x ^= basis[i]; } } ll minimize(ll x) { REPR(i, MAX_BIT) { if (basis[i] && (x ^ basis[i]) < x) { x ^= basis[i]; } } return x; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll n, m; cin >> n >> m; ll a, b, w; vvp g(n); REP(i, m) { cin >> a >> b >> w; a--, b--; g[a].push_back({b, w}); g[b].push_back({a, w}); } vll dist(n, -1); XORB basis; auto dfs = [&](auto self, ll v, ll d) -> void { dist[v] = d; for (auto [u, w] : g[v]) { if (dist[u] == -1) { self(self, u, d ^ w); } else { ll cycle = d ^ w ^ dist[u]; if (cycle != 0) basis.insert(cycle); } } }; dfs(dfs, 0, 0); ll res = dist[n - 1]; if (res != -1) res = basis.minimize(res); cout << res << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - XOR Shortest Walk |
User | harsaka |
Language | C++ 20 (gcc 12.2) |
Score | 0 |
Code Size | 2605 Byte |
Status | WA |
Exec Time | 1 ms |
Memory | 3684 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 | 3452 KiB |
hand_02.txt | AC | 1 ms | 3480 KiB |
hand_03.txt | WA | 1 ms | 3452 KiB |
hand_04.txt | AC | 1 ms | 3624 KiB |
hand_05.txt | WA | 1 ms | 3428 KiB |
hand_06.txt | WA | 1 ms | 3552 KiB |
hand_07.txt | WA | 1 ms | 3584 KiB |
hand_08.txt | WA | 1 ms | 3480 KiB |
random_01.txt | AC | 1 ms | 3360 KiB |
random_02.txt | AC | 1 ms | 3572 KiB |
random_03.txt | AC | 1 ms | 3628 KiB |
random_04.txt | AC | 1 ms | 3512 KiB |
random_05.txt | AC | 1 ms | 3492 KiB |
random_06.txt | AC | 1 ms | 3556 KiB |
random_07.txt | AC | 1 ms | 3424 KiB |
random_08.txt | AC | 1 ms | 3556 KiB |
random_09.txt | AC | 1 ms | 3500 KiB |
random_10.txt | AC | 1 ms | 3588 KiB |
random_11.txt | AC | 1 ms | 3552 KiB |
random_12.txt | AC | 1 ms | 3660 KiB |
random_13.txt | AC | 1 ms | 3612 KiB |
random_14.txt | AC | 1 ms | 3532 KiB |
random_15.txt | AC | 1 ms | 3448 KiB |
random_16.txt | AC | 1 ms | 3516 KiB |
random_17.txt | AC | 1 ms | 3592 KiB |
random_18.txt | AC | 1 ms | 3588 KiB |
random_19.txt | AC | 1 ms | 3684 KiB |
random_20.txt | AC | 1 ms | 3536 KiB |
random_21.txt | AC | 1 ms | 3544 KiB |
random_22.txt | AC | 1 ms | 3636 KiB |
sample_01.txt | AC | 1 ms | 3496 KiB |
sample_02.txt | AC | 1 ms | 3532 KiB |
sample_03.txt | AC | 1 ms | 3656 KiB |