結果
問題 |
No.3263 違法な散歩道
|
ユーザー |
|
提出日時 | 2025-09-06 15:33:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,482 bytes |
コンパイル時間 | 1,135 ms |
コンパイル使用メモリ | 103,692 KB |
実行使用メモリ | 21,520 KB |
最終ジャッジ日時 | 2025-09-06 15:33:36 |
合計ジャッジ時間 | 4,196 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 WA * 12 |
ソースコード
#include <iostream> #include <cstdint> #include <iomanip> #include <vector> #include <algorithm> #include <set> #include <map> #include <queue> using namespace std; struct Func_print { void is_true(bool yes) { cout << (yes ? "Yes" : "No") << '\n'; }; void print_v_str(vector<string> v) { for (auto s : v) { for (auto c : s) { cout << c << ' '; } cout << '\n'; } } void print_vv(vector<vector<int>> vv) { for (auto v : vv) { for (auto d : v) { cout << d << ' '; } cout << '\n'; } } }; Func_print Out;//出力用 #define REP(i, n) for (int i = 0; i < (n); i++) #define VEC(type, name, n) vector<type> name(n); REP(i, n) cin >> name.at(i) #define VV(type, name, h, w) vector<vector<type>> name(h, vector<type>(w)); REP(i, h) REP(j, w) cin >> name.at(i).at(j) #define ALL(iterable) begin(iterable), end(iterable) int main() { /////////////////////////////// //お約束 ios::sync_with_stdio(false);//printfとcoutを混在しないように注意 //doubleの桁数指定は以下を使用する //cout << fixed << setprecision() << y << endl; cin.tie(nullptr); //////////////////////////////// int N, M; cin >> N >> M; vector<vector<int>> edges(N+1, vector<int>()); REP(i, M) { int u, v; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } vector<bool> is_yiwiy9(N+1, false);//右寄りしか勝たん!! int K; cin >> K; REP(i, K) { int a; cin >> a; is_yiwiy9[a] = true; } vector<int> path; const int64_t INF = INT64_MAX; int64_t ans = INF; vector<vector<bool>> memo(N+1, vector<bool>(5, false)); auto dfs = [&](auto self, int v, int cnt_now) { if (v == N) { ans = min(ans, (int64_t)path.size() - 1); return; } for (auto nv : edges[v]) { int cnt_next = cnt_now; if (is_yiwiy9[nv]) cnt_next ++; else cnt_next = 0; if (cnt_next >= 5) continue; if (memo[nv][cnt_next]) continue; memo[nv][cnt_next] = true; path.push_back(nv); self(self, nv, cnt_next); path.pop_back(); } }; memo[1][0] = true; path.push_back(1); dfs(dfs, 1, 0); if (ans == INF) ans = -1; cout << ans << endl; }