結果

問題 No.1382 Travel in Mitaru city
ユーザー TheBookThiefTheBookThief
提出日時 2021-02-09 06:17:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 3,056 ms
コンパイル使用メモリ 171,536 KB
実行使用メモリ 10,188 KB
最終ジャッジ日時 2023-09-20 17:11:59
合計ジャッジ時間 13,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,708 KB
testcase_01 AC 3 ms
5,972 KB
testcase_02 AC 3 ms
5,672 KB
testcase_03 AC 3 ms
5,788 KB
testcase_04 AC 3 ms
5,756 KB
testcase_05 AC 3 ms
5,856 KB
testcase_06 AC 27 ms
7,352 KB
testcase_07 AC 22 ms
7,052 KB
testcase_08 AC 14 ms
6,376 KB
testcase_09 AC 30 ms
7,452 KB
testcase_10 AC 28 ms
7,444 KB
testcase_11 AC 54 ms
7,924 KB
testcase_12 AC 47 ms
8,120 KB
testcase_13 AC 50 ms
8,052 KB
testcase_14 AC 42 ms
7,920 KB
testcase_15 AC 44 ms
8,076 KB
testcase_16 AC 76 ms
9,168 KB
testcase_17 AC 74 ms
9,124 KB
testcase_18 AC 78 ms
9,328 KB
testcase_19 AC 74 ms
9,192 KB
testcase_20 AC 78 ms
9,264 KB
testcase_21 AC 78 ms
9,300 KB
testcase_22 AC 83 ms
9,188 KB
testcase_23 AC 85 ms
9,068 KB
testcase_24 AC 88 ms
9,144 KB
testcase_25 AC 82 ms
9,328 KB
testcase_26 AC 78 ms
9,116 KB
testcase_27 AC 76 ms
9,120 KB
testcase_28 AC 78 ms
9,068 KB
testcase_29 AC 82 ms
9,072 KB
testcase_30 AC 78 ms
9,252 KB
testcase_31 AC 49 ms
8,888 KB
testcase_32 AC 61 ms
9,524 KB
testcase_33 AC 56 ms
9,044 KB
testcase_34 AC 38 ms
8,036 KB
testcase_35 AC 25 ms
7,236 KB
testcase_36 AC 35 ms
8,940 KB
testcase_37 AC 9 ms
6,264 KB
testcase_38 AC 40 ms
9,196 KB
testcase_39 AC 12 ms
6,620 KB
testcase_40 AC 29 ms
8,196 KB
testcase_41 AC 34 ms
8,552 KB
testcase_42 AC 40 ms
9,096 KB
testcase_43 AC 35 ms
8,640 KB
testcase_44 AC 16 ms
7,156 KB
testcase_45 AC 33 ms
8,464 KB
testcase_46 AC 19 ms
6,812 KB
testcase_47 AC 69 ms
10,072 KB
testcase_48 AC 45 ms
8,764 KB
testcase_49 AC 73 ms
10,188 KB
testcase_50 AC 31 ms
7,700 KB
testcase_51 AC 52 ms
8,836 KB
testcase_52 AC 61 ms
9,280 KB
testcase_53 AC 14 ms
6,572 KB
testcase_54 AC 27 ms
7,356 KB
testcase_55 AC 56 ms
9,200 KB
testcase_56 AC 20 ms
6,936 KB
testcase_57 AC 39 ms
8,048 KB
testcase_58 AC 8 ms
6,324 KB
testcase_59 AC 17 ms
6,832 KB
testcase_60 AC 55 ms
9,216 KB
testcase_61 AC 4 ms
5,860 KB
testcase_62 AC 3 ms
5,904 KB
testcase_63 AC 8 ms
5,960 KB
testcase_64 AC 5 ms
5,928 KB
testcase_65 AC 4 ms
5,944 KB
testcase_66 AC 4 ms
5,752 KB
testcase_67 AC 4 ms
5,872 KB
testcase_68 AC 6 ms
5,948 KB
testcase_69 AC 5 ms
5,800 KB
testcase_70 AC 6 ms
5,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5+2;
int n,m,s,t;
int u0,v0;
vector<int> adj[MAX_N];
int p[MAX_N];
bool used[MAX_N];
priority_queue< pair<int,int> > pq;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m>>s>>t;
    for(int i=1; i<=n; i++)
    {
        cin>>p[i];
    }
    for(int i=0; i<m; i++)
    {
        cin>>u0>>v0;
        adj[u0].push_back(v0);
        adj[v0].push_back(u0);
    }
    int ans = 0;
    int val = p[s];
    used[s] = true;
    pq.push({p[s],s});
    ///cout<<endl;
    while(!pq.empty())
    {
        pair<int,int> tmp = pq.top();
        ///cout<<tmp.first<<" "<<tmp.second<<endl;
        pq.pop();
        if(val > tmp.first)
        {
            val = tmp.first;
            ans++;
        }
        for(auto x: adj[tmp.second])
        {
            if(used[x] == 0)
            {
                used[x] = 1;
                pq.push({p[x],x});
            }
        }
    }
    if(used[t])cout<<ans<<endl;
    else cout<<0<<endl;
}
0