結果
問題 | No.2712 Play more! |
ユーザー |
|
提出日時 | 2024-03-31 15:06:37 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,831 bytes |
コンパイル時間 | 2,281 ms |
コンパイル使用メモリ | 211,860 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-09-30 20:14:57 |
合計ジャッジ時間 | 3,309 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> PP; // #define MOD 1000000007 #define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define ORREP(i,n) for(ll i=(n);i>=1;--i) #define rep(i,a,b) for(ll i=(a);i<=(b);++i) #define ALL(v) (v).begin(), (v).end() #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false class BellmanFord{ // Copyright (c) 2023 0214sh7 // https://github.com/0214sh7/library/ private: typedef std::pair<std::pair<int,int>,long long> P; int V,E; // long long INF = (1LL<<61); std::vector<std::pair<std::pair<int,int>,long long>> es; public: void init(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){ //辺数をもとめる E=edge.size(); //頂点数を決定する V=N; es=edge; } BellmanFord(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){ init(N,edge); } std::vector<std::pair<long long,bool>> solve(int s){ std::vector<std::pair<long long,bool>> d; //INFで初期化する for(int i=0;i<V;i++){ d.push_back({INF,false}); } d[s].first=0; for(int j=0;j<2*V;j++){ bool update=false; for(int i=0;i<E;i++){ P k=es[i]; if(d[k.first.first].first!=INF && d[k.first.second].first>d[k.first.first].first+k.second){ d[k.first.second].first=d[k.first.first].first+k.second; if(j>=V){ d[k.first.second].second=true; } update=true; } } if(!update)break; } return d; } }; int main(void){ //cin.tie(nullptr); //ios::sync_with_stdio(false); ll N,M; cin >> N >> M; vector<ll> A(N); REP(i,N){ cin >> A[i]; } vector<ll> U(M),V(M),C(M); std::vector<std::pair<std::pair<int,int>,long long>> E; REP(i,M){ cin >> U[i] >> V[i] >> C[i]; U[i]--; V[i]--; E.push_back({{U[i],V[i]},C[i]-A[V[i]]}); } BellmanFord bellmanford(N,E); std::vector<std::pair<long long,bool>> B = bellmanford.solve(0); ll Ans = 0; for(int i=0;i<N;i++){ if(B[i].second==true){ std::cout << "inf" << endl; return 0; } } Ans += A[0]-B[N-1].first; cout << Ans << endl; return 0; }