pb_jiang

ABC408E AC

May 31st, 2025
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T>
  8. using mpq = priority_queue<T, vector<T>, greater<T>>;
  9.  
  10. namespace rngs = std::ranges;
  11. using ll = long long;
  12. using a2l = array<ll, 2>;
  13. using pll = pair<ll, ll>;
  14. using vl = vector<ll>;
  15.  
  16. void solve() {
  17.     ll n, m;
  18.     cin >> n >> m;
  19.     vector<vector<a2l>> g(n + 1);
  20.     for (ll i = 0, u, v, w; i < m; ++i) {
  21.         cin >> u >> v >> w;
  22.         g[u].push_back({v, w}), g[v].push_back({u, w});
  23.     }
  24.  
  25.     auto check_bit = [&](ll bit) -> bool {
  26.         vl vis(n + 1);
  27.         queue<ll> q;
  28.         q.push(1);
  29.         while (!q.empty()) {
  30.             auto u = q.front();
  31.             q.pop();
  32.             if (vis[u])
  33.                 continue;
  34.             vis[u] = 1;
  35.             for (auto [v, w] : g[u]) {
  36.                 if (!vis[v] && ((w | bit) == bit)) {
  37.                     q.push(v);
  38.                 }
  39.             }
  40.         }
  41.         return vis[n] == 1;
  42.     };
  43.  
  44.     ll ans = (1ll << 32) - 1;
  45.     for (ll i = 31; i >= 0; --i) {
  46.         if (check_bit(ans ^ (1ll << i)))
  47.             ans ^= (1ll << i);
  48.     }
  49.     cout << ans << '\n';
  50. }
  51.  
  52. int main(int argc, char **argv) {
  53.     std::ios::sync_with_stdio(false);
  54.     std::cin.tie(nullptr);
  55.  
  56.     solve();
  57.  
  58.     return 0;
  59. };
Advertisement
Add Comment
Please, Sign In to add comment