結果
| 問題 | No.2565 はじめてのおつかい |
| コンテスト | |
| ユーザー |
Solalyth
|
| 提出日時 | 2026-06-19 12:19:46 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 921 bytes |
| 記録 | |
| コンパイル時間 | 1,468 ms |
| コンパイル使用メモリ | 218,104 KB |
| 実行使用メモリ | 11,904 KB |
| 最終ジャッジ日時 | 2026-06-19 12:19:51 |
| 合計ジャッジ時間 | 4,867 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i, a, b) for(LL i=(a); i<(b); i++)
template <typename T> bool chmin(T& a, const T& b) { return a>b ? a=b,1 : 0; }
int main() {
int N, M; cin >> N >> M;
vector<int> E[1<<17];
rep(_, 0, M) {
int u, v; cin >> u >> v; u--; v--;
E[u].push_back(v);
}
const int inf = 1<<27;
deque<pair<int, int>> que = {{0, 0}};
int d[4][1<<17]; rep(i, 0, 4) rep(j, 0, 1<<17) { d[i][j] = inf; }
d[0][0] = 0;
while(!que.empty()) {
auto [k, i] = que.front(); que.pop_front();
for(auto j: E[i]) {
int xk = k;
if (j == N-2) { xk |= 1; }
if (j == N-1) { xk |= 2; }
if (chmin(d[xk][j], d[k][i]+1)) {
que.push_back(make_pair(xk, j));
}
}
}
if (d[3][0] == inf) { d[3][0] = -1; }
cout << d[3][0];
}
Solalyth