結果

問題 No.1382 Travel in Mitaru city
コンテスト
ユーザー siman
提出日時 2023-01-03 10:38:38
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,307 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,582 ms
コンパイル使用メモリ 151,296 KB
実行使用メモリ 404,720 KB
最終ジャッジ日時 2026-05-21 08:39:16
合計ジャッジ時間 7,548 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 TLE * 1 -- * 64
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:36:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   36 |   int P[N];
      |         ^
main.cpp:36:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:33:7: note: declared here
   33 |   int N, M, S, T;
      |       ^
main.cpp:41:17: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   41 |   vector<int> E[N + 1];
      |                 ^~~~~
main.cpp:41:17: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:33:7: note: declared here
   33 |   int N, M, S, T;
      |       ^
main.cpp:51:15: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   51 |   int visited[N + 1];
      |               ^~~~~
main.cpp:51:15: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:33:7: note: declared here
   33 |   int N, M, S, T;
      |       ^
3 warnings generated.

ソースコード

diff #
raw source code

#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