結果
問題 |
No.1449 新プロランド
|
ユーザー |
👑 ![]() |
提出日時 | 2021-03-31 16:10:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 1,139 bytes |
コンパイル時間 | 2,112 ms |
コンパイル使用メモリ | 204,656 KB |
最終ジャッジ日時 | 2025-01-20 02:03:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:16:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:19:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | int u,v,c; scanf("%d%d%d",&u,&v,&c); u--; v--; | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:23:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | rep(i,N) scanf("%d",&C[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct Edge{ int to; int d; }; using dijkstra_queue = priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>; int N,M; vector<vector<Edge>> E; int D[100][1002]; int C[100]; int main(){ scanf("%d%d",&N,&M); E.resize(N); rep(i,M){ int u,v,c; scanf("%d%d%d",&u,&v,&c); u--; v--; E[u].push_back({v,c}); E[v].push_back({u,c}); } rep(i,N) scanf("%d",&C[i]); rep(i,N) rep(d,1002) D[i][d]=-1; dijkstra_queue Q; D[0][0]=0; Q.push({0,{0,0}}); while(Q.size()){ int p=Q.top().second.first; int c=Q.top().second.second; int t=Q.top().first; Q.pop(); if(D[p][c]!=t) continue; c = min(c+C[p],1001); t += C[p]; for(Edge e:E[p]){ int nxt = t + e.d / c; if(D[e.to][c] != -1 && D[e.to][c] <= nxt) continue; D[e.to][c] = nxt; Q.push({nxt,{e.to,c}}); } } int ans=1001001001; rep(i,1002){ if(D[N-1][i]!=-1) ans=min(ans,D[N-1][i]); } printf("%d\n",ans); return 0; }