結果

問題 No.2565 はじめてのおつかい
ユーザー 沙耶花沙耶花
提出日時 2023-12-06 00:45:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 4,673 ms
コンパイル使用メモリ 265,800 KB
実行使用メモリ 14,336 KB
最終ジャッジ日時 2023-12-06 00:45:54
合計ジャッジ時間 12,297 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 99 ms
14,336 KB
testcase_04 AC 75 ms
14,336 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 54 ms
6,676 KB
testcase_07 AC 29 ms
6,676 KB
testcase_08 AC 29 ms
6,676 KB
testcase_09 AC 50 ms
6,676 KB
testcase_10 AC 35 ms
6,676 KB
testcase_11 AC 86 ms
9,728 KB
testcase_12 AC 20 ms
6,676 KB
testcase_13 AC 35 ms
6,676 KB
testcase_14 AC 59 ms
7,552 KB
testcase_15 AC 63 ms
6,784 KB
testcase_16 AC 64 ms
12,160 KB
testcase_17 AC 13 ms
6,676 KB
testcase_18 AC 19 ms
6,912 KB
testcase_19 AC 72 ms
8,704 KB
testcase_20 AC 64 ms
8,320 KB
testcase_21 AC 60 ms
8,320 KB
testcase_22 AC 39 ms
6,784 KB
testcase_23 AC 41 ms
6,676 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 62 ms
8,576 KB
testcase_26 AC 45 ms
6,676 KB
testcase_27 AC 59 ms
8,960 KB
testcase_28 AC 69 ms
8,448 KB
testcase_29 AC 82 ms
10,368 KB
testcase_30 AC 64 ms
9,600 KB
testcase_31 AC 66 ms
8,576 KB
testcase_32 AC 35 ms
6,676 KB
testcase_33 AC 61 ms
9,216 KB
testcase_34 AC 64 ms
7,680 KB
testcase_35 AC 67 ms
10,752 KB
testcase_36 AC 66 ms
9,216 KB
testcase_37 AC 40 ms
6,676 KB
testcase_38 AC 62 ms
7,680 KB
testcase_39 AC 57 ms
6,912 KB
testcase_40 AC 75 ms
10,240 KB
testcase_41 AC 80 ms
11,008 KB
testcase_42 AC 40 ms
6,676 KB
testcase_43 AC 55 ms
7,424 KB
testcase_44 AC 29 ms
6,676 KB
testcase_45 AC 15 ms
6,676 KB
testcase_46 AC 66 ms
7,040 KB
testcase_47 AC 44 ms
6,676 KB
testcase_48 AC 36 ms
6,676 KB
testcase_49 AC 19 ms
6,676 KB
testcase_50 AC 52 ms
6,676 KB
testcase_51 AC 2 ms
6,676 KB
testcase_52 AC 43 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

int main(){
	
	int n,m;
	cin>>n>>m;
	vector<vector<int>> E(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		E[a].push_back(b);
	}
	vector d(n,vector<int>(4,Inf32));
	d[0][0] = 0;
	queue<pair<int,int>> Q;
	Q.emplace(0,0);
	while(Q.size()>0){
		int x = Q.front().first,y = Q.front().second;
		Q.pop();
		rep(i,E[x].size()){
			int tx = E[x][i];
			int ty = y;
			if(tx==n-2)ty |= 1;
			if(tx==n-1)ty |= 2;
			if(d[tx][ty]==Inf32){
				d[tx][ty] = d[x][y]+1;
				Q.emplace(tx,ty);
			}
		}
	}
	int ans = d[0][3];
	if(ans==Inf32)ans =-1;
	cout<<ans<<endl;
	
	return 0;
}
0