結果
| 問題 |
No.2712 Play more!
|
| ユーザー |
maeshun
|
| 提出日時 | 2024-03-31 22:11:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,830 bytes |
| コンパイル時間 | 4,725 ms |
| コンパイル使用メモリ | 257,380 KB |
| 最終ジャッジ日時 | 2025-02-20 18:28:39 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 9 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
# include <debug_print.hpp>
# define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
# define dbg(...) (static_cast<void>(0))
#endif
int main()
{
int n, m;
cin >> n >> m;
vector<int> a(n);
rep(i,n) cin >> a[i];
vector<vector<pair<int, int>>> g(n), rev(n);
rep(i,m){
int a, b, c;
cin >> a >> b >> c;
--a;--b;
g[a].emplace_back(b,c);
rev[b].emplace_back(a,c);
}
vector<int> cnt(n);
queue<int> q;
q.push(0);
while(!q.empty()) {
int u = q.front();q.pop();
cnt[u]++;
if(u==n-1) continue;
for(auto [v, c] : g[u]) {
if(cnt[v]==0) {
q.push(v);
}
}
}
q.push(n-1);
while(!q.empty()) {
int u = q.front();q.pop();
cnt[u]++;
for(auto [v, c] :rev[u]) {
if(cnt[v]==1) {
q.push(v);
}
}
}
vector<ll> dist(n, -1e18);
dist[0] = 0;
dbg(cnt);
rep(j,2*n+1) {
bool upd = false;
rep(i,n-1){
if(cnt[i]!=2) continue;
for(auto [v, c] : g[i]) {
if(cnt[v]!=2) continue;
if(dist[v]<dist[i] + a[i]-c) {
dist[v] = dist[i] + a[i] - c;
upd = true;
}
}
}
if(j==2*n && upd) {
cout << "inf" << endl;
return 0;
}
}
cout << dist[n-1] + a[n-1] << endl;
return 0;
}
maeshun