結果

問題 No.2565 はじめてのおつかい
ユーザー momoyuumomoyuu
提出日時 2023-12-15 14:26:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 113,456 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2023-12-15 14:26:29
合計ジャッジ時間 8,126 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 73 ms
14,208 KB
testcase_04 AC 37 ms
14,208 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 42 ms
6,676 KB
testcase_07 AC 21 ms
6,676 KB
testcase_08 AC 27 ms
6,676 KB
testcase_09 AC 36 ms
6,676 KB
testcase_10 AC 31 ms
6,676 KB
testcase_11 AC 96 ms
9,728 KB
testcase_12 AC 11 ms
6,676 KB
testcase_13 AC 30 ms
6,676 KB
testcase_14 AC 64 ms
7,680 KB
testcase_15 AC 65 ms
6,912 KB
testcase_16 AC 37 ms
12,032 KB
testcase_17 AC 7 ms
6,676 KB
testcase_18 AC 11 ms
6,784 KB
testcase_19 AC 59 ms
8,704 KB
testcase_20 AC 52 ms
8,320 KB
testcase_21 AC 41 ms
8,448 KB
testcase_22 AC 18 ms
6,676 KB
testcase_23 AC 30 ms
6,676 KB
testcase_24 AC 5 ms
6,676 KB
testcase_25 AC 51 ms
8,448 KB
testcase_26 AC 28 ms
6,676 KB
testcase_27 AC 30 ms
8,832 KB
testcase_28 AC 45 ms
8,448 KB
testcase_29 AC 69 ms
10,368 KB
testcase_30 AC 34 ms
9,472 KB
testcase_31 AC 55 ms
8,576 KB
testcase_32 AC 19 ms
6,676 KB
testcase_33 AC 33 ms
9,088 KB
testcase_34 AC 54 ms
7,808 KB
testcase_35 AC 35 ms
10,624 KB
testcase_36 AC 53 ms
9,216 KB
testcase_37 AC 28 ms
6,676 KB
testcase_38 AC 29 ms
7,552 KB
testcase_39 AC 56 ms
7,040 KB
testcase_40 AC 39 ms
10,112 KB
testcase_41 AC 55 ms
10,880 KB
testcase_42 AC 29 ms
6,676 KB
testcase_43 AC 26 ms
7,296 KB
testcase_44 AC 20 ms
6,676 KB
testcase_45 AC 8 ms
6,676 KB
testcase_46 AC 70 ms
7,168 KB
testcase_47 AC 27 ms
6,676 KB
testcase_48 AC 30 ms
6,676 KB
testcase_49 AC 10 ms
6,676 KB
testcase_50 AC 27 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 18 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

#include<queue>

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n,m;
    cin>>n>>m;
    vector<vector<int>> g(n);
    for(int i = 0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        g[u].push_back(v);
    }
    vector<vector<int>> ans(n,vector<int>(4,1e9));
    ans[0][0] = 0;
    using dat = pair<int,pair<int,int>>;
    priority_queue<dat,vector<dat>,greater<dat>> que;
    que.push(make_pair(0,make_pair(0,0)));
    while(que.size()){
        int ni = que.top().second.first;
        int t = que.top().second.second;
        if(que.top().first>ans[ni][t]) {
            que.pop();
            continue;
        }
        que.pop();
        for(auto&to:g[ni]){
            int need = ans[ni][t] + 1;
            int nt = t;
            if(to==n-2) nt |= 1;
            if(to==n-1) nt |= 2;
            if(ans[to][nt]<=need) continue;
            ans[to][nt] = need;
            que.push(make_pair(need,make_pair(to,nt)));
        }
    }
    if(ans[0][3]==1e9) ans[0][3] = -1;
    cout<<ans[0][3]<<endl;

}
0