結果

問題 No.1449 新プロランド
ユーザー siman
提出日時 2021-10-27 06:24:54
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,505 bytes
コンパイル時間 3,908 ms
コンパイル使用メモリ 144,240 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 02:09:03
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 101;

int g_cost[MAX_N][MAX_N];
vector<int> E[MAX_N];

struct Node {
  int v;
  int t;
  int cost;

  Node(int v = -1, int t = -1, int cost = -1) {
    this->v = v;
    this->t = t;
    this->cost = cost;
  }

  bool operator>(const Node &n) const {
    return cost > n.cost;
  }
};

int main() {
  int N, M;
  cin >> N >> M;

  int a, b, c;
  for (int i = 0; i < M; ++i) {
    cin >> a >> b >> c;

    E[a].push_back(b);
    E[b].push_back(a);
    g_cost[a][b] = c;
    g_cost[b][a] = c;
  }

  vector<int> T(N);
  for (int i = 0; i < N; ++i) {
    cin >> T[i];
  }

  priority_queue <Node, vector<Node>, greater<Node>> pque;
  pque.push(Node(1, 0, 0));

  bool visited[N + 1][2010];
  memset(visited, false, sizeof(visited));
  int ans = INT_MAX;

  while (not pque.empty()) {
    Node node = pque.top();
    pque.pop();

    if (visited[node.v][node.t]) continue;
    visited[node.v][node.t] = true;

    if (node.v == N) {
      ans = min(ans, node.cost);
      continue;
    }

    node.t = min(2010, node.t + T[node.v - 1]);
    node.cost += T[node.v - 1];

    for (int u : E[node.v]) {
      int ncost = node.cost + g_cost[node.v][u] / node.t;
      pque.push(Node(u, node.t, ncost));
    }
  }

  cout << ans << endl;

  return 0;
}
0