結果

問題 No.2712 Play more!
ユーザー えらーめぐえらーめぐ
提出日時 2024-03-31 14:33:44
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,731 bytes
コンパイル時間 2,804 ms
コンパイル使用メモリ 255,436 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-31 14:33:49
合計ジャッジ時間 4,288 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 WA -
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 22 ms
6,548 KB
testcase_08 AC 22 ms
6,548 KB
testcase_09 AC 22 ms
6,548 KB
testcase_10 WA -
testcase_11 AC 14 ms
6,548 KB
testcase_12 AC 64 ms
6,548 KB
testcase_13 AC 18 ms
6,548 KB
testcase_14 AC 45 ms
6,548 KB
testcase_15 AC 91 ms
6,548 KB
testcase_16 AC 8 ms
6,548 KB
testcase_17 AC 4 ms
6,548 KB
testcase_18 AC 6 ms
6,548 KB
testcase_19 AC 4 ms
6,548 KB
testcase_20 AC 26 ms
6,548 KB
testcase_21 AC 13 ms
6,548 KB
testcase_22 AC 38 ms
6,548 KB
testcase_23 AC 7 ms
6,548 KB
testcase_24 AC 8 ms
6,548 KB
testcase_25 AC 5 ms
6,548 KB
testcase_26 AC 8 ms
6,548 KB
testcase_27 AC 15 ms
6,548 KB
testcase_28 WA -
testcase_29 AC 13 ms
6,548 KB
testcase_30 AC 72 ms
6,548 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
template<class T> bool chmin(T &a,T b){
    if(a>b){a = b;return true;}
    return false;
}
template<class T> bool chmax(T &a,T b){
    if(a<b){a = b;return true;}
    return false;
}

using ll = long long;
using ld = long double;

// const int INF = 1e9+5;
// const int mod = 1000000007;
const int mod = 998244353;

void no(){
    cout << "No" << endl;exit(0);
}
void yes(){
    cout << "Yes" << endl; exit(0);
}
#define all(x) x.begin(),x.end()

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

struct Edge{
    int to;
    ll w;//cost
    Edge(int to, ll w):to(to),w(w){}//コンストラクタ 頂点番号、コスト
};
using Graph = vector<vector<Edge>>;


//負の閉路があるかどうかと、ない場合はvectorを返す
pair<bool,vector<ll>> BellmanFord(Graph &G, int s){
    int N = (int)G.size();
    bool exist_negative_cycle = false;//一旦負の閉路がないことに
    vector<ll>dist(N,INF);
    dist[s]=0;
    for(int i = 0;i < N;i++){//頂点数だけ緩和をする
        bool update = false;//更新が発生したかどうか
        for(int v = 0;v < N;v++){
            if(dist[v]==INF)continue;//まだ見なくていい
            for(auto e:G[v]){
                if(chmin(dist[e.to],dist[v]+e.w)){
                    update = true;
                }
            }

        }
        if(!update)break;//既に最短経路長が求まってる
        if(i==N-1&&update)exist_negative_cycle = true;//負の閉路がある場合
    }
    return pair<bool,vector<ll>>(exist_negative_cycle,dist);

}


int main(){

    //移動時間-攻略時間を最小に

    int N,M;cin >> N >> M;
    vector<int>A(N);//攻略時間
    rep(i,N)cin >> A[i];
    Graph G(N);

    //頂点0の攻略は最後に考慮すればよい

    rep(i,M){
        int a,b,c;cin >> a >> b >> c;
        //移動と、行先の攻略時間
        a--;b--;
        G[a].emplace_back(b,c-A[b]);//移動-頂点bの攻略
    }

    auto [f,d] = BellmanFord(G,0);
    if(f){
        cout << "inf" << endl;return 0;
    }
    int res = d[N-1];
    cout << (res-A[0])*-1 << endl;
    



    // //使用例
    // int V,E,r;
    // cin >> V >> E >> r;
    // Graph G(V);
    // for(int i = 0;i < E;i++){
    //     int s,t,d;
    //     cin >> s >> t >> d;
    //     G[s].emplace_back(t,d);
    // }
    // auto [flag,dist]=BellmanFord(G,r);
    // if(flag){
    //     cout << "NEGATIVE CYCLE" << endl;
    // }
    // else{
    //     for(int i = 0;i < V;i++){
    //         if(dist[i]==INF)cout << "INF" << endl;
    //         else cout << dist[i] << endl;
    //     }
    // }


}
0