結果
| 問題 |
No.2712 Play more!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-31 14:11:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,272 bytes |
| コンパイル時間 | 2,243 ms |
| コンパイル使用メモリ | 225,632 KB |
| 最終ジャッジ日時 | 2025-02-20 17:01:51 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 WA * 2 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m; cin >> n >> m;
vector<ll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<vector<pair<int,ll>>> g(n);
for (int i = 0; i < m; ++i) {
int x,y,z; cin >> x >> y >> z;
x -= 1, y -= 1;
g[x].push_back({y, z});
}
vector<ll> dp(n, -1e18);
dp[0] = a[0];
priority_queue<pair<ll,int>> pq;
pq.push({dp[0], 0});
vector<int> cnt(n);
while (pq.size()) {
auto p = pq.top(); pq.pop();
ll score = p.first, j = p.second;
if (dp[j] != score) continue;
cnt[j] += 1;
if (cnt[j] >= 10*n) {
cout << "inf" << endl;
return 0;
}
for (auto to : g[j]) {
ll nxt = score - to.second + a[to.first];
int t = to.first;
if (dp[t] < nxt) {
dp[t] = nxt;
pq.push({nxt, t});
}
}
}
cout << dp.back() << endl;
}