結果

問題 No.1382 Travel in Mitaru city
ユーザー 沙耶花沙耶花
提出日時 2021-02-07 20:44:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 834 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 210,232 KB
実行使用メモリ 10,220 KB
最終ジャッジ日時 2023-09-17 19:30:23
合計ジャッジ時間 9,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 31 ms
5,124 KB
testcase_07 AC 25 ms
4,580 KB
testcase_08 AC 15 ms
4,376 KB
testcase_09 AC 32 ms
5,036 KB
testcase_10 AC 32 ms
4,992 KB
testcase_11 AC 63 ms
6,732 KB
testcase_12 AC 67 ms
6,912 KB
testcase_13 AC 66 ms
7,072 KB
testcase_14 AC 59 ms
6,924 KB
testcase_15 AC 63 ms
6,824 KB
testcase_16 AC 107 ms
8,840 KB
testcase_17 AC 105 ms
9,192 KB
testcase_18 AC 103 ms
8,944 KB
testcase_19 AC 105 ms
8,832 KB
testcase_20 AC 105 ms
8,840 KB
testcase_21 AC 104 ms
9,112 KB
testcase_22 AC 100 ms
8,904 KB
testcase_23 AC 104 ms
8,896 KB
testcase_24 AC 106 ms
8,880 KB
testcase_25 AC 103 ms
8,952 KB
testcase_26 AC 103 ms
9,012 KB
testcase_27 AC 105 ms
9,008 KB
testcase_28 AC 108 ms
9,036 KB
testcase_29 AC 104 ms
8,948 KB
testcase_30 AC 107 ms
9,028 KB
testcase_31 AC 72 ms
7,900 KB
testcase_32 AC 89 ms
9,080 KB
testcase_33 AC 81 ms
8,632 KB
testcase_34 AC 55 ms
6,720 KB
testcase_35 AC 35 ms
5,692 KB
testcase_36 AC 59 ms
8,124 KB
testcase_37 AC 11 ms
4,376 KB
testcase_38 AC 65 ms
8,696 KB
testcase_39 AC 18 ms
4,376 KB
testcase_40 AC 49 ms
6,988 KB
testcase_41 AC 55 ms
7,644 KB
testcase_42 AC 67 ms
8,596 KB
testcase_43 AC 58 ms
8,068 KB
testcase_44 AC 25 ms
4,884 KB
testcase_45 AC 53 ms
7,216 KB
testcase_46 AC 25 ms
5,400 KB
testcase_47 AC 96 ms
9,752 KB
testcase_48 AC 63 ms
7,748 KB
testcase_49 AC 102 ms
10,220 KB
testcase_50 AC 42 ms
6,560 KB
testcase_51 AC 66 ms
8,252 KB
testcase_52 AC 81 ms
8,904 KB
testcase_53 AC 17 ms
4,380 KB
testcase_54 AC 33 ms
5,792 KB
testcase_55 AC 78 ms
8,596 KB
testcase_56 AC 23 ms
4,896 KB
testcase_57 AC 48 ms
6,964 KB
testcase_58 AC 9 ms
4,376 KB
testcase_59 AC 23 ms
5,004 KB
testcase_60 AC 70 ms
8,632 KB
testcase_61 AC 3 ms
4,380 KB
testcase_62 AC 2 ms
4,380 KB
testcase_63 AC 7 ms
4,376 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 2 ms
4,376 KB
testcase_66 AC 3 ms
4,376 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int N,M,S,T;
vector<int> p;
vector<vector<int>> E;
int main(){
	
	cin>>N>>M>>S>>T;
	
	S--;T--;
	
	p.resize(N);
	rep(i,N){
		cin>>p[i];
	}
	
	E.resize(N);
	
	rep(i,M){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;b--;
		
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	priority_queue<pair<int,int>> Q;
	Q.emplace(p[S],S);
	
	int last = Inf;
	int ans = 0;
	
	vector<bool> visited(N,false);
	visited[S] = true;
	
	while(Q.size()>0){
		int u = Q.top().first;
		int v = Q.top().second;
		Q.pop();
		
		if(u < last){
			 last=  u;
			 ans++;
		}
		rep(i,E[v].size()){
			int x = E[v][i];
			if(visited[x])continue;
			visited[x] = true;
			Q.emplace(p[x],x);
		}
		
		
	}
	
	cout<<ans-1<<endl;
	
	return 0;
}
0