結果
問題 | No.2712 Play more! |
ユーザー |
![]() |
提出日時 | 2024-09-02 10:48:45 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,083 bytes |
コンパイル時間 | 3,446 ms |
コンパイル使用メモリ | 256,932 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-02 10:48:50 |
合計ジャッジ時間 | 5,619 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 2 |
ソースコード
#include <bits/stdc++.h>using namespace std;struct Edge {Edge() {}Edge(int from_, int to_, long long cost_, int idx_) : from(from_), to(to_), cost(cost_), idx(idx_) {}int from, to;long long cost;int idx;};struct Graph {private:int n, m;bool dir;vector<vector<Edge>> g;vector<Edge> e;public:Graph() {}Graph(int n_, bool dir_) : n(n_), m(0), dir(dir_), g(n), e(0) {}Graph(int n_) : n(n_), m(0), dir(false), g(n), e(0) {}int size() {return n;}int edgesize() {return m;}bool directed() {return dir;}void add(int u, int v, long long w) {g[u].emplace_back(u, v, w, m);e.emplace_back(u, v, w, m);if (!dir) {g[v].emplace_back(v, u, w, m);}m++;}vector<Edge> operator[](int v) {return g[v];}Edge edge(int i) {return e[i];}};pair<vector<long long>, bool> BellmanFord(Graph g, int s) {int n = g.size(), m = g.edgesize();vector<long long> dist(n, 1000000000000000000);bool negacycle = false;dist[s] = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {auto e = g.edge(j);int u = e.from, v = e.to;long long w = e.cost;if (dist[v] > dist[u] + w) {dist[v] = dist[u] + w;if (i == n - 1) {negacycle = true;}}}}return {dist, negacycle};}using lint = long long;int main() {int n, m;cin >> n >> m;vector<lint> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}Graph g(n, true);for (int i = 0; i < m; i++) {int u, v;lint w;cin >> u >> v >> w;u--;v--;g.add(u, v, w - a[v]);}auto [d, f] = BellmanFord(g, 0);if (f) {cout << "inf" << endl;} else {cout << -(d[n - 1] - a[0]) << endl;}}