結果
問題 |
No.3291 K-step Navigation
|
ユーザー |
![]() |
提出日時 | 2025-10-03 22:24:09 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,650 bytes |
コンパイル時間 | 3,506 ms |
コンパイル使用メモリ | 300,052 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-10-03 22:24:31 |
合計ジャッジ時間 | 5,373 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 WA * 12 |
ソースコード
#if __INCLUDE_LEVEL__ == 0 #include __BASE_FILE__ void Solve() { int n, m; int64_t K; int s, t; IN(n, m, K, s, t); --s, --t; vector<basic_string<int>> g(n); atcoder::dsu dsu(n); while (m--) { int i, j; IN(i, j); --i, --j; g[i] += j; g[j] += i; dsu.merge(i, j); } auto go = [&](int s) -> vector<array<int, 2>> { vector<array<int, 2>> f(n, {INF, INF}); vector<pair<int, int>> q; f[s][0] = 0; q.emplace_back(s, 0); for (int qi = 0; qi < Sz(q); ++qi) { auto [i, x] = q[qi]; for (int j : g[i]) { int y = x ^ 1; if (SetMin(f[j][y], f[i][x] + 1)) { q.emplace_back(j, y); } } } return f; }; auto fs = go(s); auto ft = go(t); if (fs[t][K % 2] < INF && fs[t][K % 2] <= K) { OUT("Yes"); return; } if (dsu.size(s) == 1 && dsu.size(t) == 1) { OUT(K == 1 ? "Yes" : "No"); return; } for (int i : Rep(0, n)) { for (int x : Rep(0, 2)) { for (int j : Rep(0, n)) { if (i == j) { continue; } int y = (K ^ x ^ 1) & 1; if (fs[i][x] < INF && ft[j][y] < INF && fs[i][x] + ft[j][y] < K) { OUT("Yes"); return; } } } } OUT("No"); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Solve(); } #elif __INCLUDE_LEVEL__ == 1 #include <bits/stdc++.h> #include <atcoder/dsu.hpp> template <class T> concept MyRange = std::ranges::range<T> && !std::convertible_to<T, std::string_view>; template <class T> concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>; namespace std { istream& operator>>(istream& is, MyRange auto&& r) { for (auto&& e : r) is >> e; return is; } istream& operator>>(istream& is, MyTuple auto&& t) { apply([&](auto&... xs) { (is >> ... >> xs); }, t); return is; } ostream& operator<<(ostream& os, MyRange auto&& r) { auto sep = ""; for (auto&& e : r) os << exchange(sep, " ") << e; return os; } ostream& operator<<(ostream& os, MyTuple auto&& t) { auto sep = ""; apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t); return os; } } // namespace std using namespace std; #define LAMBDA2(x, y, ...) ([&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; }) #define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__) #define Sz(r) int(size(r)) #define SetMin(...) LAMBDA2(x, y, y < x && (x = y, 1))(__VA_ARGS__) #define INF (INT_MAX / 2) #define IN(...) (cin >> forward_as_tuple(__VA_ARGS__)) #define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n') #endif // __INCLUDE_LEVEL__ == 1