結果

問題 No.1382 Travel in Mitaru city
ユーザー kk
提出日時 2021-02-17 18:06:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 2,541 ms
コンパイル使用メモリ 212,992 KB
実行使用メモリ 13,792 KB
最終ジャッジ日時 2023-10-12 04:46:55
合計ジャッジ時間 16,024 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 67 ms
5,340 KB
testcase_07 AC 51 ms
4,720 KB
testcase_08 AC 25 ms
4,368 KB
testcase_09 AC 73 ms
5,248 KB
testcase_10 AC 68 ms
5,280 KB
testcase_11 AC 93 ms
8,844 KB
testcase_12 AC 102 ms
9,116 KB
testcase_13 AC 112 ms
9,060 KB
testcase_14 AC 84 ms
8,676 KB
testcase_15 AC 95 ms
8,792 KB
testcase_16 AC 155 ms
12,272 KB
testcase_17 AC 154 ms
12,284 KB
testcase_18 AC 157 ms
12,128 KB
testcase_19 AC 154 ms
12,308 KB
testcase_20 AC 159 ms
12,340 KB
testcase_21 AC 157 ms
12,284 KB
testcase_22 AC 148 ms
12,184 KB
testcase_23 AC 150 ms
12,296 KB
testcase_24 AC 156 ms
12,228 KB
testcase_25 AC 150 ms
12,140 KB
testcase_26 AC 158 ms
12,188 KB
testcase_27 AC 150 ms
12,196 KB
testcase_28 AC 153 ms
12,252 KB
testcase_29 AC 149 ms
12,124 KB
testcase_30 AC 143 ms
12,284 KB
testcase_31 AC 101 ms
11,780 KB
testcase_32 AC 135 ms
13,588 KB
testcase_33 AC 123 ms
12,756 KB
testcase_34 AC 74 ms
9,892 KB
testcase_35 AC 49 ms
7,472 KB
testcase_36 AC 76 ms
12,036 KB
testcase_37 AC 11 ms
4,544 KB
testcase_38 AC 82 ms
12,760 KB
testcase_39 AC 21 ms
5,668 KB
testcase_40 AC 67 ms
10,452 KB
testcase_41 AC 70 ms
11,160 KB
testcase_42 AC 87 ms
12,896 KB
testcase_43 AC 72 ms
11,812 KB
testcase_44 AC 29 ms
6,404 KB
testcase_45 AC 65 ms
10,976 KB
testcase_46 AC 27 ms
5,996 KB
testcase_47 AC 128 ms
12,892 KB
testcase_48 AC 81 ms
10,080 KB
testcase_49 AC 145 ms
13,792 KB
testcase_50 AC 50 ms
7,752 KB
testcase_51 AC 109 ms
11,864 KB
testcase_52 AC 130 ms
13,536 KB
testcase_53 AC 26 ms
5,664 KB
testcase_54 AC 51 ms
7,992 KB
testcase_55 AC 122 ms
13,184 KB
testcase_56 AC 34 ms
6,460 KB
testcase_57 AC 78 ms
9,852 KB
testcase_58 AC 11 ms
4,388 KB
testcase_59 AC 35 ms
6,472 KB
testcase_60 AC 118 ms
12,868 KB
testcase_61 AC 3 ms
4,352 KB
testcase_62 AC 1 ms
4,356 KB
testcase_63 AC 10 ms
4,348 KB
testcase_64 AC 4 ms
4,348 KB
testcase_65 AC 2 ms
4,352 KB
testcase_66 AC 3 ms
4,352 KB
testcase_67 AC 3 ms
4,352 KB
testcase_68 AC 5 ms
4,352 KB
testcase_69 AC 3 ms
4,348 KB
testcase_70 AC 6 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s, --t;

  vector<int> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i];
  
  vector<vector<int> > edges(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    edges[a].emplace_back(b);
    edges[b].emplace_back(a);
  }

  int cur = p[s];
  int ret = 0;
  set<int> x;
  set<pair<int, int> > y;
  y.emplace(p[s], s);
  
  while (y.size()) {
    auto itr = y.end();
    int v = (--itr)->second;
    x.insert(v);
    y.erase(itr);
    if (cur > p[v]) {
      cur = p[v];
      ++ret;
    }
    for (int w: edges[v]) {
      if (!x.count(w))
        y.emplace(p[w], w);
    }
  }
  cout << ret << endl;
  
  return 0;
}
0