結果

問題 No.1382 Travel in Mitaru city
ユーザー 👑 emthrmemthrm
提出日時 2021-02-07 21:19:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 2,298 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 215,984 KB
実行使用メモリ 14,064 KB
最終ジャッジ日時 2023-09-17 20:22:41
合計ジャッジ時間 8,664 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 42 ms
5,004 KB
testcase_07 AC 33 ms
4,716 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 46 ms
5,164 KB
testcase_10 AC 43 ms
5,188 KB
testcase_11 AC 62 ms
7,268 KB
testcase_12 AC 66 ms
7,512 KB
testcase_13 AC 72 ms
7,520 KB
testcase_14 AC 58 ms
7,216 KB
testcase_15 AC 60 ms
7,252 KB
testcase_16 AC 101 ms
9,652 KB
testcase_17 AC 97 ms
9,604 KB
testcase_18 AC 101 ms
9,608 KB
testcase_19 AC 101 ms
9,604 KB
testcase_20 AC 103 ms
9,552 KB
testcase_21 AC 104 ms
9,660 KB
testcase_22 AC 104 ms
9,784 KB
testcase_23 AC 102 ms
9,696 KB
testcase_24 AC 100 ms
9,592 KB
testcase_25 AC 102 ms
9,540 KB
testcase_26 AC 83 ms
9,536 KB
testcase_27 AC 83 ms
9,816 KB
testcase_28 AC 85 ms
9,700 KB
testcase_29 AC 86 ms
9,624 KB
testcase_30 AC 78 ms
9,488 KB
testcase_31 AC 57 ms
8,276 KB
testcase_32 AC 66 ms
9,336 KB
testcase_33 AC 64 ms
8,932 KB
testcase_34 AC 42 ms
7,092 KB
testcase_35 AC 27 ms
5,640 KB
testcase_36 AC 40 ms
8,292 KB
testcase_37 AC 8 ms
4,376 KB
testcase_38 AC 45 ms
8,936 KB
testcase_39 AC 13 ms
4,608 KB
testcase_40 AC 34 ms
7,424 KB
testcase_41 AC 38 ms
8,064 KB
testcase_42 AC 45 ms
8,740 KB
testcase_43 AC 40 ms
8,404 KB
testcase_44 AC 17 ms
5,112 KB
testcase_45 AC 37 ms
7,704 KB
testcase_46 AC 25 ms
6,076 KB
testcase_47 AC 95 ms
13,204 KB
testcase_48 AC 63 ms
10,288 KB
testcase_49 AC 105 ms
14,064 KB
testcase_50 AC 40 ms
8,000 KB
testcase_51 AC 64 ms
8,304 KB
testcase_52 AC 75 ms
9,388 KB
testcase_53 AC 17 ms
4,780 KB
testcase_54 AC 32 ms
5,896 KB
testcase_55 AC 74 ms
9,072 KB
testcase_56 AC 23 ms
5,168 KB
testcase_57 AC 47 ms
6,912 KB
testcase_58 AC 8 ms
4,376 KB
testcase_59 AC 23 ms
5,112 KB
testcase_60 AC 67 ms
8,752 KB
testcase_61 AC 3 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 8 ms
4,380 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 1 ms
4,376 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 4 ms
4,376 KB
testcase_69 AC 2 ms
4,380 KB
testcase_70 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

struct UnionFind {
  UnionFind(int n) : data(n, -1) {}

  int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); }

  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (data[u] > data[v]) std::swap(u, v);
    data[u] += data[v];
    data[v] = u;
    return true;
  }

  bool same(int u, int v) { return root(u) == root(v); }

  int size(int ver) { return -data[root(ver)]; }

private:
  std::vector<int> data;
};

int main() {
  int n, m, s, t; cin >> n >> m >> s >> t; --s; --t;
  vector<int> p(n); REP(i, n) cin >> p[i];
  vector<int> ps = p;
  sort(ALL(ps));
  ps.erase(unique(ALL(ps)), ps.end());
  REP(i, n) p[i] = lower_bound(ALL(ps), p[i]) - ps.begin();
  vector<vector<int>> graph(n);
  while (m--) {
    int a, b; cin >> a >> b; --a; --b;
    graph[a].emplace_back(b);
    graph[b].emplace_back(a);
  }
  int y = 0;
  vector<bool> visited(n, false);
  visited[s] = true;
  set<pair<int, int>> que;
  que.emplace(-p[s], s);
  for (int i = p[s]; i >= 0; --i) {
    bool exist = false;
    while (!que.empty() && -que.begin()->first >= i) {
      auto [_, v] = *que.begin();
      que.erase(que.begin());
      visited[v] = true;
      if (p[v] == i) exist = true;
      for (int e : graph[v]) {
        if (!visited[e]) que.emplace(-p[e], e);
      }
    }
    y += exist && i < p[s];
  }
  cout << y << '\n';
  return 0;
}
0