Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T>
- using mpq = priority_queue<T, vector<T>, greater<T>>;
- namespace rngs = std::ranges;
- using ll = long long;
- using a2l = array<ll, 2>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- void solve() {
- ll n, m;
- cin >> n >> m;
- vector<vector<a2l>> g(n + 1);
- for (ll i = 0, u, v, w; i < m; ++i) {
- cin >> u >> v >> w;
- g[u].push_back({v, w}), g[v].push_back({u, w});
- }
- auto check_bit = [&](ll bit) -> bool {
- vl vis(n + 1);
- queue<ll> q;
- q.push(1);
- while (!q.empty()) {
- auto u = q.front();
- q.pop();
- if (vis[u])
- continue;
- vis[u] = 1;
- for (auto [v, w] : g[u]) {
- if (!vis[v] && ((w | bit) == bit)) {
- q.push(v);
- }
- }
- }
- return vis[n] == 1;
- };
- ll ans = (1ll << 32) - 1;
- for (ll i = 31; i >= 0; --i) {
- if (check_bit(ans ^ (1ll << i)))
- ans ^= (1ll << i);
- }
- cout << ans << '\n';
- }
- int main(int argc, char **argv) {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment