結果

問題 No.1301 Strange Graph Shortest Path
ユーザー snow39snow39
提出日時 2020-11-27 22:23:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,127 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 115,716 KB
実行使用メモリ 20,848 KB
最終ジャッジ日時 2023-10-09 21:23:53
合計ジャッジ時間 8,706 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 WA -
testcase_03 AC 117 ms
14,024 KB
testcase_04 AC 214 ms
19,108 KB
testcase_05 AC 112 ms
14,348 KB
testcase_06 AC 179 ms
17,352 KB
testcase_07 AC 165 ms
16,428 KB
testcase_08 AC 115 ms
13,960 KB
testcase_09 AC 172 ms
16,844 KB
testcase_10 WA -
testcase_11 AC 180 ms
17,432 KB
testcase_12 AC 186 ms
18,028 KB
testcase_13 AC 154 ms
15,952 KB
testcase_14 AC 165 ms
16,280 KB
testcase_15 AC 165 ms
16,036 KB
testcase_16 AC 213 ms
19,308 KB
testcase_17 AC 173 ms
16,864 KB
testcase_18 AC 157 ms
15,516 KB
testcase_19 AC 189 ms
17,500 KB
testcase_20 AC 192 ms
17,712 KB
testcase_21 AC 163 ms
16,656 KB
testcase_22 AC 188 ms
18,376 KB
testcase_23 AC 158 ms
16,216 KB
testcase_24 AC 185 ms
18,204 KB
testcase_25 AC 195 ms
18,448 KB
testcase_26 AC 175 ms
16,748 KB
testcase_27 AC 173 ms
17,168 KB
testcase_28 AC 120 ms
14,712 KB
testcase_29 WA -
testcase_30 AC 196 ms
18,048 KB
testcase_31 AC 197 ms
18,540 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 220 ms
20,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int N,M;
vector<vector<pair<int,ll>>> cg;
vector<vector<pair<int,ll>>> dg;
const ll INF=1e18;

map<pair<int,int>,int> mp;

ll dijkstra(vector<int> &path){
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
  PQ.push(mkp(0,0));
  vector<ll> dist(N,INF);
  vector<int> prev(N,-1);
  dist[0]=0;
  while(!PQ.empty()){
    auto f=PQ.top();
    PQ.pop();
    int now=f.second;
    ll d=f.first;
    if(dist[now]<d) continue;

    for(auto e:cg[now]){
      int to=e.first;
      ll cost=e.second;
      if(mp.count(minmax(now,to))) continue;
      if(dist[to]>dist[now]+cost){
        prev[to]=now;
        dist[to]=dist[now]+cost;
        PQ.push(mkp(dist[to],to));
      }
    }
    for(auto e:dg[now]){
      int to=e.first;
      ll cost=e.second;
      if(mp.count(minmax(now,to))==false) continue;
      if(dist[to]>dist[now]+cost){
        prev[to]=now;
        dist[to]=dist[now]+cost;
        PQ.push(mkp(dist[to],to));
      }
    }
  }

  int now=N-1;
  while(prev[now]!=-1){
    path.push_back(now);
    now=prev[now];
  }
  path.push_back(now);
  reverse(all(path));
  return dist[N-1];
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N>>M;
  cg.resize(N);
  dg.resize(N);
  rep(i,M){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;b--;
    cg[a].push_back(mkp(b,c));
    cg[b].push_back(mkp(a,c));
    dg[a].push_back(mkp(b,d));
    dg[b].push_back(mkp(a,d));
  }

  vector<int> onepath;
  ll ares=dijkstra(onepath);
  for(int i=0;i+1<onepath.size();i++) mp[minmax(onepath[i],onepath[i+1])]=1;
  vector<int> twopath;
  ll bres=dijkstra(twopath);
  cout<<ares+bres<<endl;


  return 0;
}
0