結果
| 問題 |
No.2565 はじめてのおつかい
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2023-12-03 05:55:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 170 ms / 2,000 ms |
| コード長 | 1,699 bytes |
| コンパイル時間 | 4,510 ms |
| コンパイル使用メモリ | 257,160 KB |
| 最終ジャッジ日時 | 2025-02-18 06:38:44 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
int main(){
int n, m; cin >> n >> m;
vector ikeru(n, vector<int>(0));
rep(i,0,m){
int u, v; cin >> u >> v;
u--; v--;
ikeru[u].push_back(v);
}
vector dep(n, vector<int>(4));
vector tansaku(n, vector<bool>(4));
deque<pair<int,int>> mada = {pair(0, 0)};
tansaku[0][0] = 1;
while(!mada.empty()){
auto [i,dat] = mada.front();
mada.pop_front();
for (int j:ikeru[i]){
int tmp = dat;
if (j==n-2) tmp |= 1;
if (j==n-1) tmp |= 2;
if (tansaku[j][tmp]) continue;
tansaku[j][tmp] = 1;
mada.push_back(pair(j,tmp));
dep[j][tmp] = dep[i][dat] + 1;
}
}
if (!tansaku[0][3]) cout << -1 << '\n';
else cout << dep[0][3] << '\n';
}
shobonvip