結果
問題 | No.859 路線A、路線B、路線C |
ユーザー |
|
提出日時 | 2020-05-23 06:34:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,524 bytes |
コンパイル時間 | 1,932 ms |
コンパイル使用メモリ | 204,572 KB |
最終ジャッジ日時 | 2025-01-10 15:15:34 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 1 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; template<class T> struct edge{ int to; T wt; edge(int to,const T& wt):to(to),wt(wt){} }; template<class T> using weighted_graph=vector<vector<edge<T>>>; template<class T> void add_edge(weighted_graph<T>& G,int u,int v,const T& wt){ G[u].emplace_back(v,wt); G[v].emplace_back(u,wt); } template<class T> vector<T> Dijkstra(const weighted_graph<T>& G,int s){ const T INF=numeric_limits<T>::max(); int n=G.size(); vector<T> d(n,INF); d[s]=0; priority_queue<pair<T,int>> Q; Q.emplace(0,s); while(!Q.empty()){ T d0=-Q.top().first; int u=Q.top().second; Q.pop(); if(d0>d[u]) continue; for(const auto& e:G[u]){ int v=e.to; if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v); } } return d; } int main(){ int x,y,z; cin>>x>>y>>z; char c1,c2; int t1,t2; cin>>c1>>t1>>c2>>t2; weighted_graph<lint> G(8); add_edge<lint>(G,0,1,1); add_edge<lint>(G,0,2,1); add_edge<lint>(G,1,2,1); add_edge<lint>(G,3,4,1); add_edge<lint>(G,3,5,1); add_edge<lint>(G,4,5,1); add_edge<lint>(G,0,3,x-1); add_edge<lint>(G,1,4,y-1); add_edge<lint>(G,2,5,z-1); auto f=[&](char c,int t,int u){ if(c=='A'){ add_edge<lint>(G,0,u,t-1); add_edge<lint>(G,3,u,x-t); } else if(c=='B'){ add_edge<lint>(G,1,u,t-1); add_edge<lint>(G,4,u,y-t); } else{ add_edge<lint>(G,2,u,t-1); add_edge<lint>(G,5,u,z-t); } }; f(c1,t1,6); f(c2,t2,7); cout<<Dijkstra(G,6)[7]<<'\n'; return 0; }