結果

問題 No.2565 はじめてのおつかい
ユーザー throughthrough
提出日時 2023-12-07 19:08:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 1,761 ms
コンパイル使用メモリ 178,276 KB
実行使用メモリ 28,396 KB
最終ジャッジ日時 2023-12-07 19:09:01
合計ジャッジ時間 6,432 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 155 ms
28,396 KB
testcase_04 AC 61 ms
28,396 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 51 ms
11,008 KB
testcase_07 AC 25 ms
7,424 KB
testcase_08 AC 27 ms
8,320 KB
testcase_09 AC 44 ms
10,112 KB
testcase_10 AC 31 ms
8,960 KB
testcase_11 AC 92 ms
18,136 KB
testcase_12 AC 14 ms
6,548 KB
testcase_13 AC 29 ms
8,576 KB
testcase_14 AC 54 ms
13,416 KB
testcase_15 AC 57 ms
12,544 KB
testcase_16 AC 74 ms
21,796 KB
testcase_17 AC 12 ms
6,548 KB
testcase_18 AC 18 ms
10,324 KB
testcase_19 AC 74 ms
16,252 KB
testcase_20 AC 62 ms
15,040 KB
testcase_21 AC 62 ms
15,132 KB
testcase_22 AC 34 ms
11,136 KB
testcase_23 AC 39 ms
11,264 KB
testcase_24 AC 7 ms
6,548 KB
testcase_25 AC 60 ms
15,420 KB
testcase_26 AC 36 ms
10,496 KB
testcase_27 AC 68 ms
16,112 KB
testcase_28 AC 89 ms
15,752 KB
testcase_29 AC 90 ms
19,452 KB
testcase_30 AC 67 ms
17,524 KB
testcase_31 AC 67 ms
15,672 KB
testcase_32 AC 33 ms
10,496 KB
testcase_33 AC 66 ms
16,804 KB
testcase_34 AC 70 ms
14,316 KB
testcase_35 AC 81 ms
19,492 KB
testcase_36 AC 76 ms
16,768 KB
testcase_37 AC 39 ms
10,880 KB
testcase_38 AC 63 ms
14,340 KB
testcase_39 AC 57 ms
12,416 KB
testcase_40 AC 88 ms
19,236 KB
testcase_41 AC 90 ms
20,496 KB
testcase_42 AC 45 ms
10,240 KB
testcase_43 AC 51 ms
13,416 KB
testcase_44 AC 25 ms
8,448 KB
testcase_45 AC 13 ms
6,656 KB
testcase_46 AC 67 ms
13,312 KB
testcase_47 AC 37 ms
8,832 KB
testcase_48 AC 31 ms
8,704 KB
testcase_49 AC 14 ms
6,548 KB
testcase_50 AC 39 ms
9,728 KB
testcase_51 AC 2 ms
6,548 KB
testcase_52 AC 23 ms
9,984 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   33 |         auto [idx,dis] = todo.front(); todo.pop();
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
#define rep(i, n) for(ll i = 0; i < n; i++)

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    ll n, m; cin >> n >> m;
    vector<vector<ll>> Graph(4*n);
    vector<ll> vis(4*n,-1);
    rep(i,m) {
        ll u, v; cin >> u >> v; u--; v--;
        Graph[u].emplace_back(v);
        Graph[n+u].emplace_back(n+v);
        Graph[2*n+u].emplace_back(2*n+v);
        Graph[3*n+u].emplace_back(3*n+v);
    }
    Graph[n-2].emplace_back(n+(n-2));
    Graph[n-1].emplace_back(2*n+(n-1));
    Graph[n+(n-1)].emplace_back(3*n+(n-1));
    Graph[2*n+(n-2)].emplace_back(3*n+(n-2));

    queue<P> todo;
    todo.push(P(0,0));
    while( !todo.empty() ) {
        auto [idx,dis] = todo.front(); todo.pop();
        if( vis[idx] != -1 ) continue;
        vis[idx] = dis;
        for(auto to:Graph[idx]) {
            if( vis[to] != -1 ) continue;
            todo.push(P(to,dis+1));
        }
    }
    cout << (vis[3*n] == -1 ? -1 : vis[3*n]-2) << endl;
    
    return 0;
}
0