結果

問題 No.2712 Play more!
ユーザー haihamabossuhaihamabossu
提出日時 2024-03-31 15:33:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,673 bytes
コンパイル時間 2,583 ms
コンパイル使用メモリ 221,392 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:33:41
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 63 ms
6,676 KB
testcase_08 AC 62 ms
6,676 KB
testcase_09 AC 63 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 17 ms
6,676 KB
testcase_12 AC 40 ms
6,676 KB
testcase_13 AC 12 ms
6,676 KB
testcase_14 AC 64 ms
6,676 KB
testcase_15 AC 102 ms
6,676 KB
testcase_16 AC 9 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 7 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 18 ms
6,676 KB
testcase_21 AC 13 ms
6,676 KB
testcase_22 AC 43 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 11 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 16 ms
6,676 KB
testcase_27 AC 15 ms
6,676 KB
testcase_28 WA -
testcase_29 AC 15 ms
6,676 KB
testcase_30 AC 85 ms
6,676 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 4 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void solve() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector g(n, vector<pair<ll, ll>>());
  vector r(n, vector<ll>());
  rep(i, m) {
    ll u, v, c;
    cin >> u >> v >> c, u--, v--;
    g[u].emplace_back(v, c);
    r[v].push_back(u);
  }
  vector<bool> vis1(n, false), vis2(n, false);
  {
    vis1[0] = vis2[n - 1] = true;
    auto dfs1 = [&](auto self, ll u, ll p) -> void {
      for (const auto &[v, c] : g[u]) {
        if (v == p || vis1[v])
          continue;
        vis1[v] = true;
        self(self, v, u);
      }
    };
    auto dfs2 = [&](auto self, ll u, ll p) -> void {
      for (const auto v : r[u]) {
        if (v == p || vis2[v])
          continue;
        vis2[v] = true;
        self(self, v, u);
      }
    };
    dfs1(dfs1, 0, -1);
    dfs2(dfs2, n - 1, -1);
  }
  vector<ll> score(n, 0);
  bool updated = true;
  ll update_count = 0;
  while (updated) {
    updated = false;
    update_count += 1;
    if (update_count > n + 5) {
      cout << "inf\n";
      return;
    }
    vector<ll> nex = score;
    rep(u, n) if (vis1[u] && vis2[u]) {
      for (const auto &[v, c] : g[u])
        if (vis1[v] && vis2[v]) {
          ll now = score[u] - a[u] + c;
          if (now < nex[v]) {
            updated = true;
            nex[v] = now;
          }
        }
    }
    score = nex;
  }
  cout << -score[n - 1] + a[n - 1] << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0