結果
問題 | No.2712 Play more! |
ユーザー | 👑 binap |
提出日時 | 2024-03-31 14:39:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 3,036 bytes |
コンパイル時間 | 4,236 ms |
コンパイル使用メモリ | 275,184 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-09-30 23:47:55 |
合計ジャッジ時間 | 5,918 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 55 ms
6,820 KB |
testcase_08 | AC | 54 ms
6,816 KB |
testcase_09 | AC | 54 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 24 ms
6,820 KB |
testcase_12 | AC | 100 ms
6,816 KB |
testcase_13 | AC | 14 ms
6,820 KB |
testcase_14 | AC | 36 ms
6,820 KB |
testcase_15 | AC | 136 ms
6,820 KB |
testcase_16 | AC | 8 ms
6,816 KB |
testcase_17 | AC | 5 ms
6,820 KB |
testcase_18 | AC | 15 ms
6,820 KB |
testcase_19 | AC | 5 ms
6,816 KB |
testcase_20 | AC | 27 ms
6,820 KB |
testcase_21 | AC | 12 ms
6,820 KB |
testcase_22 | AC | 77 ms
6,820 KB |
testcase_23 | AC | 7 ms
6,816 KB |
testcase_24 | AC | 14 ms
6,816 KB |
testcase_25 | AC | 5 ms
6,820 KB |
testcase_26 | AC | 20 ms
6,816 KB |
testcase_27 | AC | 17 ms
6,816 KB |
testcase_28 | AC | 6 ms
6,816 KB |
testcase_29 | AC | 15 ms
6,816 KB |
testcase_30 | AC | 76 ms
6,820 KB |
testcase_31 | AC | 6 ms
6,820 KB |
testcase_32 | AC | 7 ms
6,816 KB |
testcase_33 | AC | 2 ms
6,820 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 1 ms
6,820 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} long long const INF = 1001001001001001001; template<typename T> struct Edge{ T cost; int from, to; bool operator<(const Edge<T>& right) const{ return this->cost < right.cost; } }; template<typename T> struct BellmanFord{ bool initialized; int n; int m; vector<T> dist; vector<Edge<T>> G; BellmanFord(int _n) : initialized(false), n(_n), m(0), dist(_n, INF) {} void add_edge(int from, int to, T cost){ G.push_back((Edge<T>){cost, from, to}); m++; } void init(int start){ initialized = true; sort(G.begin(), G.end()); dist[start] = 0; rep(time, n + 5){ bool change = false; rep(i, m){ auto e = G[i]; if(dist[e.from] + e.cost < dist[e.to]){ dist[e.to] = dist[e.from] + e.cost; change = true; } } if(!change) break; if(change) if(time > n){ rep(i, n) dist[i] = -INF; return; } } } T get_dist(int from, int to){ if(!initialized) init(from); return dist[to]; } }; int main(){ int n, m; cin >> n >> m; vector<long long> a(n); cin >> a; BellmanFord<long long> graph(2 * n); rep(i, n) graph.add_edge(i, n + i, -a[i]); vector<tuple<int, int, int>> G; vector<vector<int>> retro(n); rep(i, m){ int u, v, c; cin >> u >> v >> c; u--; v--; G.emplace_back(u, v, c); retro[v].push_back(u); } vector<int> need(n); queue<int> q; q.push(n - 1); while(q.size()){ int from = q.front(); q.pop(); if(need[from]) continue; need[from] = 1; for(int to : retro[from]){ q.push(to); } } // cout << need; for(auto [u, v, c] : G){ if(need[u] == 1 and need[v] == 1) graph.add_edge(n + u, v, c); } long long ans = graph.get_dist(0, 2 * n - 1); if(ans == -INF) cout << "inf\n"; else cout << -ans << "\n"; return 0; }