結果

問題 No.2565 はじめてのおつかい
ユーザー shobonvipshobonvip
提出日時 2023-12-03 05:55:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,699 bytes
コンパイル時間 4,626 ms
コンパイル使用メモリ 270,344 KB
実行使用メモリ 21,252 KB
最終ジャッジ日時 2023-12-03 05:55:56
合計ジャッジ時間 9,924 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 149 ms
21,252 KB
testcase_04 AC 86 ms
21,252 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 60 ms
7,040 KB
testcase_07 AC 31 ms
6,676 KB
testcase_08 AC 32 ms
6,676 KB
testcase_09 AC 55 ms
6,676 KB
testcase_10 AC 56 ms
7,040 KB
testcase_11 AC 103 ms
13,952 KB
testcase_12 AC 20 ms
6,676 KB
testcase_13 AC 36 ms
6,676 KB
testcase_14 AC 65 ms
10,368 KB
testcase_15 AC 66 ms
9,088 KB
testcase_16 AC 71 ms
18,672 KB
testcase_17 AC 15 ms
6,676 KB
testcase_18 AC 25 ms
9,728 KB
testcase_19 AC 84 ms
12,288 KB
testcase_20 AC 71 ms
11,648 KB
testcase_21 AC 69 ms
11,776 KB
testcase_22 AC 38 ms
9,216 KB
testcase_23 AC 44 ms
8,960 KB
testcase_24 AC 9 ms
6,676 KB
testcase_25 AC 104 ms
12,032 KB
testcase_26 AC 43 ms
8,320 KB
testcase_27 AC 69 ms
12,800 KB
testcase_28 AC 76 ms
11,776 KB
testcase_29 AC 102 ms
15,208 KB
testcase_30 AC 71 ms
13,952 KB
testcase_31 AC 90 ms
12,032 KB
testcase_32 AC 39 ms
8,448 KB
testcase_33 AC 68 ms
13,312 KB
testcase_34 AC 71 ms
10,624 KB
testcase_35 AC 74 ms
16,000 KB
testcase_36 AC 88 ms
13,312 KB
testcase_37 AC 43 ms
8,704 KB
testcase_38 AC 63 ms
10,624 KB
testcase_39 AC 60 ms
9,216 KB
testcase_40 AC 80 ms
14,956 KB
testcase_41 AC 91 ms
16,256 KB
testcase_42 AC 44 ms
7,808 KB
testcase_43 AC 57 ms
10,112 KB
testcase_44 AC 32 ms
6,676 KB
testcase_45 AC 17 ms
6,676 KB
testcase_46 AC 72 ms
9,344 KB
testcase_47 AC 46 ms
6,676 KB
testcase_48 AC 40 ms
6,676 KB
testcase_49 AC 20 ms
6,676 KB
testcase_50 AC 54 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 44 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';

}

0