結果

問題 No.1382 Travel in Mitaru city
ユーザー siman
提出日時 2023-01-03 10:38:38
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,307 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 142,716 KB
実行使用メモリ 405,048 KB
最終ジャッジ日時 2024-11-27 01:47:41
合計ジャッジ時間 69,480 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48 TLE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int v;
  int X;
  int Y;

  Node(int v = -1, int X = -1, int Y = -1) {
    this->v = v;
    this->X = X;
    this->Y = Y;
  }

  bool operator>(const Node &n) const {
    return X < n.X;
  }
};

int main() {
  int N, M, S, T;
  cin >> N >> M >> S >> T;

  int P[N];
  for (int i = 0; i < N; ++i) {
    cin >> P[i];
  }

  vector<int> E[N + 1];
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    E[a].push_back(b);
    E[b].push_back(a);
  }

  priority_queue <Node, vector<Node>, greater<Node>> pque;
  pque.push(Node(S, P[S - 1], 0));
  int visited[N + 1];
  memset(visited, -1, sizeof(visited));
  int ans = 0;

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (visited[node.v] >= node.Y) continue;
    visited[node.v] = node.Y;
    ans = max(ans, node.Y);

    for (int u : E[node.v]) {
      int p = P[u - 1];
      Node next(u, node.X, node.Y);

      if (node.X > p) {
        next.X = p;
        next.Y += 1;
      }

      pque.push(next);
    }
  }

  cout << ans << endl;

  return 0;
}
0