結果
問題 | No.2565 はじめてのおつかい |
ユーザー | NATTO |
提出日時 | 2023-12-02 16:15:40 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 3,185 bytes |
コンパイル時間 | 5,333 ms |
コンパイル使用メモリ | 314,004 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-09-26 20:03:25 |
合計ジャッジ時間 | 7,566 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 37 ms
11,008 KB |
testcase_04 | AC | 28 ms
11,008 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 22 ms
5,504 KB |
testcase_07 | AC | 13 ms
5,376 KB |
testcase_08 | AC | 12 ms
5,376 KB |
testcase_09 | AC | 20 ms
5,376 KB |
testcase_10 | AC | 14 ms
5,376 KB |
testcase_11 | AC | 31 ms
7,936 KB |
testcase_12 | AC | 8 ms
5,376 KB |
testcase_13 | AC | 14 ms
5,376 KB |
testcase_14 | AC | 22 ms
6,528 KB |
testcase_15 | AC | 23 ms
6,272 KB |
testcase_16 | AC | 23 ms
9,344 KB |
testcase_17 | AC | 6 ms
5,376 KB |
testcase_18 | AC | 8 ms
5,632 KB |
testcase_19 | AC | 26 ms
7,424 KB |
testcase_20 | AC | 23 ms
6,912 KB |
testcase_21 | AC | 23 ms
7,040 KB |
testcase_22 | AC | 14 ms
5,760 KB |
testcase_23 | AC | 16 ms
5,632 KB |
testcase_24 | AC | 4 ms
5,376 KB |
testcase_25 | AC | 25 ms
7,040 KB |
testcase_26 | AC | 16 ms
5,504 KB |
testcase_27 | AC | 23 ms
7,296 KB |
testcase_28 | AC | 25 ms
7,168 KB |
testcase_29 | AC | 27 ms
8,320 KB |
testcase_30 | AC | 24 ms
7,808 KB |
testcase_31 | AC | 23 ms
7,168 KB |
testcase_32 | AC | 14 ms
5,504 KB |
testcase_33 | AC | 23 ms
7,552 KB |
testcase_34 | AC | 24 ms
6,784 KB |
testcase_35 | AC | 24 ms
8,448 KB |
testcase_36 | AC | 23 ms
7,552 KB |
testcase_37 | AC | 14 ms
5,632 KB |
testcase_38 | AC | 24 ms
6,656 KB |
testcase_39 | AC | 20 ms
5,888 KB |
testcase_40 | AC | 28 ms
8,192 KB |
testcase_41 | AC | 29 ms
8,704 KB |
testcase_42 | AC | 16 ms
5,376 KB |
testcase_43 | AC | 22 ms
6,400 KB |
testcase_44 | AC | 12 ms
5,376 KB |
testcase_45 | AC | 7 ms
5,376 KB |
testcase_46 | AC | 25 ms
6,272 KB |
testcase_47 | AC | 17 ms
5,376 KB |
testcase_48 | AC | 14 ms
5,376 KB |
testcase_49 | AC | 8 ms
5,376 KB |
testcase_50 | AC | 18 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
testcase_52 | AC | 15 ms
5,376 KB |
ソースコード
#pragma region header #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; // clang-format off struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast; inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } template <typename T> istream &operator>>(istream &is, pair<T, T> &p) { is >> p.first >> p.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto &x : v) os << x << " "; os << endl; return os; } // templetes //alias using ull = unsigned long long; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vvb = vector<vb>; using vs = vector<string>; using pll = pair<ll, ll>; //define short #define vec vector #define all(obs) (obs).begin(), (obs).end() #define YESNO(cond) (cond) ? cout << "YES" << endl : cout << "NO" << endl; #define YesNo(cond) (cond) ? cout << "Yes" << endl : cout << "No" << endl; #define yesno(cond) (cond) ? cout << "yes" << endl : cout << "no" << endl; #define sortv(obs) sort(all(obs)) #define rsortv(obs) reverse(sort(all(obs))) #define bitu(n,i) (((n)>>(i))&1) #define dig10(n) to_string(n).size() #define bcnt(n) __builtin_popcount(n) #define bcntll(n) __builtin_popcountll(n) #define F first #define S second #define pb push_back #define pq priority_queue //define loop #define rep(i, a,b) for(ll i = a; i < (b); i++) #define rrep(i, a,b) for(ll i = a; i >= (b); i--) //define INF const ll INF = 1e18; template <typename T1,typename T2> inline void chmin(T1 &a,T2 b){ if(a>b) a = b; } template <typename T1,typename T2> inline void chmax(T1 &a,T2 b){ if(a<b) a = b; } #pragma endregion header // clang-format on int main(){ ll n,m; cin>>n>>m; vvll g(n); rep(i,0,m){ ll a,b; cin>>a>>b; a--;b--; g[a].pb(b); } vll dist0(n,INF),distn(n,INF),distnmi(n,INF); dist0[0]=0; distn[n-1]=0; distnmi[n-2]=0; queue<ll> q; q.push(0); while(!q.empty()){ ll v=q.front(); q.pop(); for(auto nv:g[v]){ if(dist0[nv]==INF){ dist0[nv]=dist0[v]+1; q.push(nv); } } } q.push(n-1); while(!q.empty()){ ll v=q.front(); q.pop(); for(auto nv:g[v]){ if(distn[nv]==INF){ distn[nv]=distn[v]+1; q.push(nv); } } } q.push(n-2); while(!q.empty()){ ll v=q.front(); q.pop(); for(auto nv:g[v]){ if(distnmi[nv]==INF){ distnmi[nv]=distnmi[v]+1; q.push(nv); } } } ll ans=INF; chmin(ans,dist0[n-1]+distn[n-2]+distnmi[0]); chmin(ans,dist0[n-2]+distnmi[n-1]+distn[0]); if(ans==INF) ans=-1; cout<<ans<<endl; }