結果

問題 No.2712 Play more!
ユーザー nonon
提出日時 2024-03-31 15:09:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,166 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 201,492 KB
最終ジャッジ日時 2025-02-20 17:40:47
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int N,M,A[2525];
vector<pair<int,long>>G[2525];
long H[2525];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // int ti=clock();
    cin>>N>>M;
    for(int i=0;i<N;i++)cin>>A[i];
    for(;M--;)
    {
        int u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        G[u].push_back(make_pair(v,w));
    }
    for(int i=0;i<N;i++)H[i]=-1L<<55;
    priority_queue<pair<long,int>>q;
    q.push(make_pair(A[0],0));
    H[0]=A[0];
    while(!q.empty())
    {
        // double t=(double)(clock()-ti)/CLOCKS_PER_SEC;
        // if(t>1.5)
        // {
        //     cout<<"inf"<<endl;
        //     return 0;
        // }
        auto[d,u]=q.top();
        q.pop();
        if(H[u]>d)continue;
        if(u==N-1)continue;
        for(auto[v,w]:G[u])
        {
            if(H[v]<d-w+A[v])
            {
                if(-(1L<<55)<H[v])
                {
                    cout<<"inf"<<endl;
                    return 0;
                }
                H[v]=d-w+A[v];
                q.push(make_pair(H[v],v));
            }
        }
    }
    assert(-(1L<<55)<H[N-1]);
    cout<<H[N-1]<<endl;
}
0