Submission #68256456
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#include <iostream>
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {return os<<'(' <<p.first<<", "<<p.second<<')';}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {os<<'[';for(auto it=v.begin();it!=v.end();++it){os<<*it; if(next(it)!=v.end()){os<<", ";}}return os<<']';}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& vv) {os<<"[\n";for(auto it=vv.begin();it!=vv.end();++it){os<<" "<<*it;if(next(it)!=vv.end()){os<<",\n";}else{os<<"\n";}}return os<<"]";}
#define dump(x) cerr << #x << " = " << (x) << '\n'
#else
#define dump(x) (void)0
#endif
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vector<T>, greater<T>>;
#define out(x) cout<<x<<'\n'
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define OVERLOAD_REP(_1,_2,_3,name,...) name
#define REP1(i,n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
template<class T> inline bool chmin(T& a, T b) {if(a > b){a = b; return true;} else {return false;}};
template<class T> inline bool chmax(T& a, T b) {if(a < b){a = b; return true;} else {return false;}};
const ll INF=(1LL<<60);
const ll mod=998244353;
using Graph = vector<vector<ll>>;
using Network = vector<vector<pair<ll,ll>>>;
using Grid = vector<string>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy2[8] = {1, 0, -1, 1, -1, 1, 0, -1};
void solve() {
ll N, M;
cin >> N >> M;
Network G(N);
rep(i, M) {
ll u, v, w;
cin >> u >> v >> w;
--u; --v;
G[u].emplace_back(v, w);
G[v].emplace_back(u, w);
}
ll ans = (1LL << 31) - 1;
for (int b = 30; b >= 0; --b) {
ll mask = (1LL << b);
bitset<200001> seen(0);
seen[0] = 1;
queue<ll> q;
q.push(0);
while (!q.empty()) {
ll v = q.front();
q.pop();
bool reached = false;
for (auto& [u, w] : G[v]) {
if ((ans | w) == ans && (w & mask) == 0 && !seen[u]) {
seen[u] = 1;
q.push(u);
if (u == N - 1) {
reached = true;
break;
}
}
}
if (reached) break;
}
if (seen[N - 1]) {
ans ^= mask;
}
}
out(ans);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int t = 1;
while (t--) {
solve();
}
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Minimum OR Path |
User |
tatesoto |
Language |
C++ 23 (gcc 12.2) |
Score |
450 |
Code Size |
3119 Byte |
Status |
AC |
Exec Time |
467 ms |
Memory |
18080 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
450 / 450 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_00.txt |
AC |
1 ms |
3572 KiB |
00_sample_01.txt |
AC |
1 ms |
3544 KiB |
00_sample_02.txt |
AC |
1 ms |
3460 KiB |
01_handmade_00.txt |
AC |
1 ms |
3548 KiB |
01_handmade_01.txt |
AC |
1 ms |
3464 KiB |
01_handmade_02.txt |
AC |
27 ms |
9636 KiB |
01_handmade_03.txt |
AC |
27 ms |
9800 KiB |
01_handmade_04.txt |
AC |
1 ms |
3664 KiB |
01_handmade_05.txt |
AC |
1 ms |
3468 KiB |
01_handmade_06.txt |
AC |
1 ms |
3560 KiB |
01_handmade_07.txt |
AC |
77 ms |
14572 KiB |
01_handmade_08.txt |
AC |
77 ms |
14700 KiB |
01_handmade_09.txt |
AC |
77 ms |
14648 KiB |
02_random_00.txt |
AC |
39 ms |
12552 KiB |
02_random_01.txt |
AC |
39 ms |
11360 KiB |
02_random_02.txt |
AC |
25 ms |
9256 KiB |
02_random_03.txt |
AC |
54 ms |
13956 KiB |
02_random_04.txt |
AC |
60 ms |
13972 KiB |
02_random_05.txt |
AC |
43 ms |
12452 KiB |
02_random_06.txt |
AC |
48 ms |
12692 KiB |
02_random_07.txt |
AC |
58 ms |
15468 KiB |
02_random_08.txt |
AC |
58 ms |
17088 KiB |
02_random_09.txt |
AC |
34 ms |
12252 KiB |
02_random_10.txt |
AC |
63 ms |
16336 KiB |
02_random_11.txt |
AC |
92 ms |
16740 KiB |
02_random_12.txt |
AC |
66 ms |
15776 KiB |
02_random_13.txt |
AC |
116 ms |
17868 KiB |
02_random_14.txt |
AC |
76 ms |
17120 KiB |
02_random_15.txt |
AC |
44 ms |
12548 KiB |
02_random_16.txt |
AC |
44 ms |
12424 KiB |
02_random_17.txt |
AC |
235 ms |
12260 KiB |
02_random_18.txt |
AC |
129 ms |
12268 KiB |
02_random_19.txt |
AC |
83 ms |
18008 KiB |
02_random_20.txt |
AC |
467 ms |
18080 KiB |
02_random_21.txt |
AC |
249 ms |
18004 KiB |