結果

問題 No.2739 Time is money
ユーザー tobbietobbie
提出日時 2024-04-23 21:51:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 173,312 KB
実行使用メモリ 20,440 KB
最終ジャッジ日時 2024-04-23 21:51:47
合計ジャッジ時間 9,386 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 157 ms
13,568 KB
testcase_03 AC 268 ms
17,536 KB
testcase_04 AC 147 ms
13,024 KB
testcase_05 AC 196 ms
13,184 KB
testcase_06 AC 259 ms
15,944 KB
testcase_07 AC 327 ms
20,096 KB
testcase_08 AC 332 ms
20,224 KB
testcase_09 AC 356 ms
20,352 KB
testcase_10 AC 280 ms
19,712 KB
testcase_11 AC 334 ms
20,440 KB
testcase_12 AC 291 ms
18,908 KB
testcase_13 AC 310 ms
18,800 KB
testcase_14 WA -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long int;
#define INF 1e18+7

struct Edge {
  int to;
  double dist;
  Edge(int to, double dist) : to(to), dist(dist) {}
};

vector<double> dijkstra(int N, vector<vector<Edge>> &graph) {
  vector<double> distance(N, INF);
  priority_queue<pair<double, int>,
                 vector<pair<double, int>>,
                 greater<pair<double, int>>> q;
  distance[0] = 0;
  q.push({0, 0});
  while (!q.empty()) {
    pair<double, int> p = q.top();
    q.pop();
    double path_now = p.first;
    int p_now = p.second;
    for (Edge e : graph[p_now]) {
      double path_new = path_now + e.dist;
      int p_new = e.to;
      if (path_new < distance[p_new]) {
	distance[p_new] = path_new;
	q.push({path_new, p_new});
      }
    }
  }
  return distance;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<vector<Edge>> g(N);
  rep(i, M) {
    int u, v, C, T;
    cin >> u >> v >> C >> T;
    u--; v--;
    g[u].push_back({v, (double)C/X + T});
    g[v].push_back({u, (double)C/X + T});
  }
  vector<double> s = dijkstra(N, g);
  if (s[N-1] < INF)
    cout << (ll)(s[N-1] + (1 - 1e-10)) << endl;
  else
    cout << -1 << endl;
  return 0;
}
0