結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー yansi819yansi819
提出日時 2024-04-12 09:29:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,254 bytes
コンパイル時間 4,193 ms
コンパイル使用メモリ 266,708 KB
実行使用メモリ 18,676 KB
最終ジャッジ日時 2024-04-12 09:38:10
合計ジャッジ時間 20,564 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,756 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 104 ms
8,956 KB
testcase_05 AC 86 ms
8,192 KB
testcase_06 AC 16 ms
6,940 KB
testcase_07 AC 21 ms
6,944 KB
testcase_08 AC 103 ms
8,960 KB
testcase_09 AC 87 ms
8,192 KB
testcase_10 WA -
testcase_11 AC 81 ms
8,192 KB
testcase_12 WA -
testcase_13 AC 61 ms
8,192 KB
testcase_14 WA -
testcase_15 AC 69 ms
7,936 KB
testcase_16 WA -
testcase_17 AC 51 ms
7,296 KB
testcase_18 AC 83 ms
7,920 KB
testcase_19 AC 151 ms
9,472 KB
testcase_20 AC 28 ms
6,940 KB
testcase_21 AC 59 ms
7,552 KB
testcase_22 WA -
testcase_23 AC 95 ms
8,704 KB
testcase_24 AC 134 ms
9,856 KB
testcase_25 AC 139 ms
9,600 KB
testcase_26 AC 131 ms
9,704 KB
testcase_27 AC 135 ms
9,692 KB
testcase_28 AC 132 ms
9,728 KB
testcase_29 AC 135 ms
9,728 KB
testcase_30 AC 136 ms
9,812 KB
testcase_31 AC 134 ms
9,728 KB
testcase_32 AC 135 ms
9,600 KB
testcase_33 AC 169 ms
9,684 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 TLE -
testcase_38 RE -
testcase_39 TLE -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int N, M, H[101010];
vector<int> G[101010];

void bfs(int start, int goal, int s) {
  ll ans1 = 0;
  queue<tuple<int, ll, bool>> que1;
  que1.push({start, 0, false});
  map<pair<int, int>, bool> vis1;
  bool flag1 = false;
  while (!que1.empty()) {
    auto &[u, c, f] = que1.front(); que1.pop();
    if (u == goal) {
      flag1 = true;
      ans1 = max(ans1, c);
      continue;
    }
    for (auto v: G[u]) {
      if (s == 0 && u > v) continue;
      if (s == 1 && u < v) continue;
      if (f && H[u] < H[v]) continue;
      ll c1 = c;
      bool f1 = f;
      if(vis1[{min(u, v), max(u, v)}]) continue;
      vis1[{min(u, v), max(u, v)}] = true;
      if (H[u] < H[v]) {
        c1 += abs(H[v] - H[u]);
        f1 = true;
      } else {
        f1 = false;
      }
      que1.push({v, c1, f1});
    }
  }
  cout << (flag1 ? ans1: -1) << endl;
}

int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; i++) cin >> H[i];
  for (int i = 1; i <= M; i++) {
    int x, y; cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  bfs(1, N, 0);
  bfs(N, 1, 1);
  return 0;
}
0