結果

問題 No.2565 はじめてのおつかい
ユーザー maeshunmaeshun
提出日時 2023-12-02 15:22:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,217 bytes
コンパイル時間 6,208 ms
コンパイル使用メモリ 267,568 KB
実行使用メモリ 14,336 KB
最終ジャッジ日時 2023-12-02 15:22:33
合計ジャッジ時間 8,361 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 91 ms
14,336 KB
testcase_04 AC 70 ms
14,336 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 51 ms
6,548 KB
testcase_07 AC 31 ms
6,548 KB
testcase_08 AC 27 ms
6,548 KB
testcase_09 AC 46 ms
6,548 KB
testcase_10 AC 33 ms
6,548 KB
testcase_11 AC 80 ms
9,728 KB
testcase_12 AC 20 ms
6,548 KB
testcase_13 AC 33 ms
6,548 KB
testcase_14 AC 55 ms
7,552 KB
testcase_15 AC 54 ms
6,784 KB
testcase_16 AC 68 ms
12,160 KB
testcase_17 AC 14 ms
6,548 KB
testcase_18 AC 19 ms
6,912 KB
testcase_19 AC 68 ms
8,704 KB
testcase_20 AC 58 ms
8,320 KB
testcase_21 AC 57 ms
8,320 KB
testcase_22 AC 33 ms
6,784 KB
testcase_23 AC 37 ms
6,656 KB
testcase_24 AC 9 ms
6,548 KB
testcase_25 AC 61 ms
8,576 KB
testcase_26 AC 37 ms
6,548 KB
testcase_27 AC 56 ms
8,960 KB
testcase_28 AC 75 ms
8,448 KB
testcase_29 AC 78 ms
10,368 KB
testcase_30 AC 58 ms
9,600 KB
testcase_31 AC 59 ms
8,576 KB
testcase_32 AC 31 ms
6,548 KB
testcase_33 AC 56 ms
9,216 KB
testcase_34 AC 59 ms
7,680 KB
testcase_35 AC 64 ms
10,752 KB
testcase_36 AC 57 ms
9,216 KB
testcase_37 AC 35 ms
6,548 KB
testcase_38 AC 54 ms
7,680 KB
testcase_39 AC 49 ms
6,912 KB
testcase_40 AC 66 ms
10,240 KB
testcase_41 AC 73 ms
11,008 KB
testcase_42 AC 39 ms
6,548 KB
testcase_43 AC 52 ms
7,424 KB
testcase_44 AC 28 ms
6,548 KB
testcase_45 AC 15 ms
6,548 KB
testcase_46 AC 58 ms
7,040 KB
testcase_47 AC 45 ms
6,548 KB
testcase_48 AC 33 ms
6,548 KB
testcase_49 AC 18 ms
6,548 KB
testcase_50 AC 48 ms
6,548 KB
testcase_51 AC 2 ms
6,548 KB
testcase_52 AC 39 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        --a;--b;
        g[a].push_back(b);
    }
    const int INF = 1e9;
    vector<vector<int>> dist(n, vector<int>(1<<2, INF));
    queue<pair<int, int>> q;
    dist[0][0] = 0;
    q.push({0,0});
    while(!q.empty()){
        auto [u, s] = q.front();q.pop();
        for(int v : g[u]){
            int ns = s;
            if(v==n-2) ns|=1;
            if(v==n-1) ns|=2;
            if(dist[v][ns]==INF) {
                dist[v][ns] = dist[u][s] + 1;
                q.emplace(v,ns);
            }
        }
    }
    int ans = dist[0][3];
    if(ans==INF) ans = -1;
    cout << ans << endl;
    return 0;
}
0