結果
| 問題 |
No.2916 累進コスト最小化
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2024-10-04 22:36:43 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 301 ms / 3,500 ms |
| コード長 | 2,182 bytes |
| コンパイル時間 | 4,520 ms |
| コンパイル使用メモリ | 322,796 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-05 01:06:42 |
| 合計ジャッジ時間 | 8,552 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
template <typename T> struct Graph {
struct edge {
int to;
T r, w;
};
int N;
vector<vector<edge>> G;
vector<T> dist;
vector<int> prever;
Graph(int n) { init(n); }
T inf() {
if (is_same_v<T, int>)
return 1e9;
else
return 1e18;
}
T zero() { return T(0); }
void init(int n) {
N = n;
G.resize(N);
dist.resize(N, inf());
}
void add_edge(int s, int t, T r, T w) {
edge e;
e.to = t;
e.r = r;
e.w = w;
G[s].push_back(e);
}
void dijkstra(int s, T c) {
rep(i, 0, N) dist[i] = -1;
prever = vector<int>(N, -1);
dist[s] = c;
priority_queue<pair<T, int>> q;
q.push({c, s});
while (!q.empty()) {
int now;
T nowdist;
tie(nowdist, now) = q.top();
q.pop();
if (dist[now] < nowdist)
continue;
for (auto e : G[now]) {
T cost = nowdist / e.r + e.w;
T nextdist = nowdist - cost;
if (dist[e.to] < nextdist && nextdist >= 0) {
dist[e.to] = nextdist;
prever[e.to] = now;
q.push({nextdist, e.to});
}
}
}
}
vector<int> get_path(int t) { // tへの最短路構築
if (dist[t] >= inf())
return {-1};
vector<int> path;
for (; t != -1; t = prever[t]) {
path.push_back(t);
}
reverse(path.begin(), path.end());
return path;
}
};
int main() {
int n, m;
ll c;
cin >> n >> m >> c;
Graph<ll> g(n);
rep(i, 0, m) {
int a, b;
ll c, d;
cin >> a >> b >> c >> d;
a--;
b--;
g.add_edge(a, b, c, d);
g.add_edge(b, a, c, d);
}
rep(i, 1, c + 1) {
g.dijkstra(0, i);
cout << g.dist[n - 1] << endl;
}
}
SnowBeenDiding