結果
問題 |
No.2916 累進コスト最小化
|
ユーザー |
|
提出日時 | 2024-10-04 23:17:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 113 ms / 3,500 ms |
コード長 | 941 bytes |
コンパイル時間 | 2,221 ms |
コンパイル使用メモリ | 207,236 KB |
最終ジャッジ日時 | 2025-02-24 15:37:54 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M,C; cin >> N >> M >> C; vector<vector<tuple<int,int,int>>> Graph(N); for(int i=0; i<M; i++){ int u,v; cin >> u >> v; u--; v--; int r,w; cin >> r >> w; Graph.at(u).push_back({v,r,w}); Graph.at(v).push_back({u,r,w}); } for(int i=1; i<=C; i++){ vector<int> dist(N,-1); dist.at(0) = i; priority_queue<pair<int,int>> Q; Q.push({dist.at(0),0}); while(Q.size()){ auto [nowc,pos] = Q.top(); Q.pop(); for(auto [to,r,w] : Graph.at(pos)){ int cost = nowc/r+w; if(dist.at(to) < nowc-cost){ dist.at(to) = nowc-cost; Q.push({dist.at(to),to}); } } } cout << dist.at(N-1) << "\n"; } }