結果
問題 | No.1449 新プロランド |
ユーザー |
![]() |
提出日時 | 2021-03-31 23:23:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 2,216 bytes |
コンパイル時間 | 2,178 ms |
コンパイル使用メモリ | 189,328 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 02:01:31 |
合計ジャッジ時間 | 3,290 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
/*** @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;}