結果

問題 No.2739 Time is money
ユーザー tobbietobbie
提出日時 2024-04-23 21:51:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,263 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 178,980 KB
実行使用メモリ 24,864 KB
最終ジャッジ日時 2024-11-06 04:07:41
合計ジャッジ時間 10,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 WA * 1 TLE * 1 -- * 4
権限があれば一括ダウンロードができます

ソースコード

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