結果

問題 No.1449 新プロランド
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-03-31 23:23:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 2,216 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 186,256 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 16:51:16
合計ジャッジ時間 3,112 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 17 ms
4,380 KB
testcase_06 AC 12 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 6 ms
4,384 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 8 ms
4,384 KB
testcase_17 AC 9 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 18 ms
4,376 KB
testcase_28 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.03.31 23:22:59
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;




template<typename T>
struct Dijkstra {
private:
    int V;
    vector<int> P;
    struct edge { int to; T cost; };
    vector<vector<edge>> G;
public:
    const T inf = numeric_limits<T>::max();
    
    
    vector<vector<T>> d; 
    Dijkstra() {}
    Dijkstra(int V) : V(V) {
        G.resize(V);
        P.resize(V);
    }
    
    Dijkstra<T>& operator=(const Dijkstra<T>& obj) {
        this->V = obj.V;
        this->G = obj.G;
        this->d = obj.d;
        return *this;
    }
    
    
    void add_edge(int from, int to, T weight, bool directed = false) {
        G[from].push_back({to,weight});
        if (!directed) G[to].push_back({from,weight});
    }
    
    
    int add_vertex() {
        G.push_back(vector<edge>());
        return V++;
    }
    void set_vertex(int v, int p) {
        P[v] = p;
    }
    void build(int s) {
        d.assign(V, vector<T>(1002,INT_FAST16_MAX)); 
        typedef tuple<T, int, int> Q; 
        priority_queue<Q, vector<Q>, greater<Q>> pq;
        d[s][0] = 0; 
        pq.push(Q(d[s][0], s, 0)); 
        while (!pq.empty()) {
            Q p = pq.top(); pq.pop();
            int v = get<1>(p);
            int q = get<2>(p);
            
            if (d[v][q] < get<0>(p)) continue; 
            for (const edge &e : G[v])
            {
                
                if (d[e.to][min(1001,q+P[v])] > d[v][q] + e.cost/(q+P[v]) + P[v]) {
                    d[e.to][min(1001,q+P[v])] = d[v][q] + e.cost/(q+P[v]) + P[v];
                    pq.push(Q(d[e.to][min(1001,q+P[v])], e.to, min(1001,q+P[v])));
                }
            }
        }
    }
};
int main() {
    int n,m;cin >> n >> m;
    Dijkstra<ll> g(n);
    for (int i = 0; i < m; i++) {
        int a,b,c;cin >> a >> b >> c;
        a--;b--;
        g.add_edge(a,b,c);
    }
    for (int i = 0; i < n; i++) {
        int t;cin >> t;
        g.set_vertex(i,t);
    }
    g.build(0);
    ll ans = g.inf;
    for (int i = 0; i < g.d[n-1].size(); i++) {
        ans = min(ans,g.d[n-1][i]);
    }
    cout << ans << endl;
    return 0;
}
0