結果
| 問題 | No.2565 はじめてのおつかい | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-12-07 19:08:54 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 109 ms / 2,000 ms | 
| コード長 | 1,200 bytes | 
| コンパイル時間 | 1,813 ms | 
| コンパイル使用メモリ | 177,436 KB | 
| 実行使用メモリ | 28,212 KB | 
| 最終ジャッジ日時 | 2024-09-27 02:17:54 | 
| 合計ジャッジ時間 | 5,247 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 50 | 
コンパイルメッセージ
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();
      |              ^
            
            ソースコード
#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;
}
            
            
            
        