結果
問題 |
No.2565 はじめてのおつかい
|
ユーザー |
![]() |
提出日時 | 2023-12-15 14:26:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 65 ms / 2,000 ms |
コード長 | 1,160 bytes |
コンパイル時間 | 1,346 ms |
コンパイル使用メモリ | 114,696 KB |
実行使用メモリ | 14,080 KB |
最終ジャッジ日時 | 2024-09-27 06:25:06 |
合計ジャッジ時間 | 4,842 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#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; }