結果

問題 No.2712 Play more!
ユーザー takumi152takumi152
提出日時 2024-03-31 15:24:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 1,031 ms
コンパイル使用メモリ 108,016 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:24:16
合計ジャッジ時間 2,391 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 WA -
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 22 ms
6,676 KB
testcase_08 AC 23 ms
6,676 KB
testcase_09 AC 22 ms
6,676 KB
testcase_10 WA -
testcase_11 AC 14 ms
6,676 KB
testcase_12 AC 45 ms
6,676 KB
testcase_13 AC 16 ms
6,676 KB
testcase_14 AC 39 ms
6,676 KB
testcase_15 AC 77 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 23 ms
6,676 KB
testcase_21 AC 9 ms
6,676 KB
testcase_22 AC 31 ms
6,676 KB
testcase_23 AC 5 ms
6,676 KB
testcase_24 AC 8 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 5 ms
6,676 KB
testcase_27 AC 18 ms
6,676 KB
testcase_28 AC 22 ms
6,676 KB
testcase_29 AC 10 ms
6,676 KB
testcase_30 AC 64 ms
6,676 KB
testcase_31 AC 24 ms
6,676 KB
testcase_32 AC 21 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

struct Edge {
  int from, to;
  ll cost;
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;
  vector<vector<Edge>> edges(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    ll c;
    cin >> u >> v >> c;
    u--; v--;
    edges[u].push_back(Edge({u, v, c - a[v]}));
  }

  vector<ll> dist(n, 1e18);
  dist[0] = -a[0];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (auto &e: edges[j]) {
        if (dist[e.from] + e.cost < dist[e.to]) {
          dist[e.to] = dist[e.from] + e.cost;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (auto &e: edges[i]) {
      if (dist[e.from] + e.cost < dist[e.to]) {
        cout << "inf" << endl;
        return 0;
      }
    }
  }

  cout << -dist[n - 1] << endl;

  return 0;
}
0