提出 #66333081
ソースコード 拡げる
// Author: Andimeo
// Date: 2025-5-31 19:56:29
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define tc int tt, qq = 0; cin >> tt; while(qq++ < tt)
#define cs cout << "Case " << qq << ": "
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using hash_t = uint64_t;
class DSU {
private:
vector<int> parent, rank, sz;
int n;
public:
DSU(int n) : parent(n), rank(n, 0), n(n), sz(n) {
for (int i = 0; i < n; i++) parent[i] = i, sz[i] = 1;
}
int find(int x) {
if (x != parent[x]) parent[x] = find(parent[x]);
return parent[x];
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) return;
if (rank[x] > rank[y]) parent[y] = x, sz[x] += sz[y];
else if (rank[x] < rank[y]) parent[x] = y, sz[y] += sz[x];
else parent[y] = x, rank[x] += 1, sz[x] += sz[y];
}
int size(int x) {
return sz[find(x)];
}
};
void solve() {
int n, m; cin >> n >> m;
vector<vector<array<int, 2>>> adj(n);
for (int i = 0; i < m; i++) {
int u, v, w; cin >> u >> v >> w; u--; v--;
adj[u].pb({v, w}); adj[v].pb({u, w});
}
int ans = (1 << 30) - 1;
for (int b = 29; b >= 0; b--) {
int mask = ans ^ (1 << b);
DSU dsu(n);
for (int u = 0; u < n; u++) {
for (auto [v, w] : adj[u]) {
if (!((~mask) & w)) {
dsu.merge(u, v);
}
}
}
if (dsu.find(0) == dsu.find(n-1)) {
ans = mask;
}
}
cout << ans << endl;
}
signed main() {
speed
//tc {
solve();
//}
return 0;
}
提出情報
提出日時
2025-05-31 21:31:52+0900
問題
E - Minimum OR Path
ユーザ
cvs
言語
C++ 17 (Clang 16.0.6)
得点
450
コード長
2792 Byte
結果
AC
実行時間
740 ms
メモリ
23016 KiB
コンパイルエラー
./Main.cpp:51:41: warning: field 'n' will be initialized after field 'sz' [-Wreorder-ctor]
DSU(int n) : parent(n), rank(n, 0), n(n), sz(n) {
^~~~ ~~~~~
sz(n) n(n)
./Main.cpp:49:9: warning: private field 'n' is not used [-Wunused-private-field]
int n;
^
2 warnings generated.
ジャッジ結果
セット名
Sample
All
得点 / 配点
0 / 0
450 / 450
結果
セット名
テストケース
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
ケース名
結果
実行時間
メモリ
00_sample_00.txt
AC
1 ms
3492 KiB
00_sample_01.txt
AC
1 ms
3496 KiB
00_sample_02.txt
AC
1 ms
3436 KiB
01_handmade_00.txt
AC
1 ms
3508 KiB
01_handmade_01.txt
AC
1 ms
3488 KiB
01_handmade_02.txt
AC
41 ms
9612 KiB
01_handmade_03.txt
AC
47 ms
9612 KiB
01_handmade_04.txt
AC
1 ms
3640 KiB
01_handmade_05.txt
AC
1 ms
3516 KiB
01_handmade_06.txt
AC
1 ms
3448 KiB
01_handmade_07.txt
AC
266 ms
15784 KiB
01_handmade_08.txt
AC
269 ms
15752 KiB
01_handmade_09.txt
AC
265 ms
15840 KiB
02_random_00.txt
AC
328 ms
15516 KiB
02_random_01.txt
AC
189 ms
13128 KiB
02_random_02.txt
AC
53 ms
9352 KiB
02_random_03.txt
AC
205 ms
15304 KiB
02_random_04.txt
AC
247 ms
15552 KiB
02_random_05.txt
AC
222 ms
13868 KiB
02_random_06.txt
AC
188 ms
13644 KiB
02_random_07.txt
AC
310 ms
17872 KiB
02_random_08.txt
AC
534 ms
20388 KiB
02_random_09.txt
AC
315 ms
14952 KiB
02_random_10.txt
AC
335 ms
18548 KiB
02_random_11.txt
AC
480 ms
19236 KiB
02_random_12.txt
AC
280 ms
17448 KiB
02_random_13.txt
AC
383 ms
21280 KiB
02_random_14.txt
AC
431 ms
20596 KiB
02_random_15.txt
AC
77 ms
12844 KiB
02_random_16.txt
AC
246 ms
15304 KiB
02_random_17.txt
AC
415 ms
15224 KiB
02_random_18.txt
AC
334 ms
15356 KiB
02_random_19.txt
AC
499 ms
23012 KiB
02_random_20.txt
AC
740 ms
22916 KiB
02_random_21.txt
AC
604 ms
23016 KiB