結果

問題 No.1301 Strange Graph Shortest Path
ユーザー monnumonnu
提出日時 2021-04-19 22:42:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,880 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 181,860 KB
実行使用メモリ 12,596 KB
最終ジャッジ日時 2023-09-17 08:31:16
合計ジャッジ時間 9,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 143 ms
8,976 KB
testcase_04 AC 211 ms
12,056 KB
testcase_05 AC 150 ms
9,200 KB
testcase_06 AC 186 ms
11,188 KB
testcase_07 AC 170 ms
10,432 KB
testcase_08 AC 143 ms
9,000 KB
testcase_09 AC 176 ms
10,860 KB
testcase_10 WA -
testcase_11 AC 185 ms
11,068 KB
testcase_12 AC 193 ms
11,416 KB
testcase_13 AC 168 ms
10,148 KB
testcase_14 AC 170 ms
10,460 KB
testcase_15 AC 167 ms
10,192 KB
testcase_16 AC 207 ms
12,180 KB
testcase_17 AC 179 ms
10,508 KB
testcase_18 AC 161 ms
9,848 KB
testcase_19 AC 179 ms
11,240 KB
testcase_20 AC 191 ms
11,588 KB
testcase_21 AC 176 ms
10,428 KB
testcase_22 AC 199 ms
11,988 KB
testcase_23 AC 174 ms
10,316 KB
testcase_24 AC 193 ms
11,516 KB
testcase_25 AC 198 ms
11,944 KB
testcase_26 AC 178 ms
10,672 KB
testcase_27 AC 184 ms
10,940 KB
testcase_28 AC 151 ms
9,356 KB
testcase_29 WA -
testcase_30 AC 191 ms
11,512 KB
testcase_31 AC 199 ms
11,708 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 180 ms
11,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MAX 200003
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> u(M),v(M);
  vector<ll> c(M),d(M);
  for(int i=0;i<M;i++){
    cin>>u[i]>>v[i]>>c[i]>>d[i];
    u[i]--;
    v[i]--;
  }

  Graph G(N);
  for(int i=0;i<M;i++){
    G[u[i]].push_back(make_pair(v[i],i));
    G[v[i]].push_back(make_pair(u[i],i));
  }

  vector<ll> dist(N,INF);
  dist[0]=0;
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
  pq.push(make_pair(dist[0],0));
  while(!pq.empty()){
    int v=pq.top().second;
    ll l=pq.top().first;
    pq.pop();
    if(l>dist[v]){
      continue;
    }
    for(auto p:G[v]){
      int nv=p.first;
      int e=p.second;
      if(dist[v]+c[e]<dist[nv]){
        dist[nv]=dist[v]+c[e];
        pq.push(make_pair(dist[nv],nv));
      }
    }
  }

  int x=N-1;
  vector<bool> used(M,false);
  while(x!=0){
    for(auto p:G[x]){
      int nv=p.first;
      int e=p.second;
      if(dist[x]==dist[nv]+c[e]){
        x=nv;
        used[e]=true;
        break;
      }
    }
  }

  ll ans=dist[N-1];
  for(int i=0;i<N-1;i++){
    dist[i]=INF;
  }
  dist[N-1]=0;
  pq.push(make_pair(dist[N-1],N-1));
  while(!pq.empty()){
    int v=pq.top().second;
    ll l=pq.top().first;
    pq.pop();
    if(l>dist[v]){
      continue;
    }
    for(auto p:G[v]){
      int nv=p.first;
      int e=p.second;
      if(used[e]==true){
        if(dist[v]+d[e]<dist[nv]){
          dist[nv]=dist[v]+d[e];
          pq.push(make_pair(dist[nv],nv));
        }
      }else{
        if(dist[v]+c[e]<dist[nv]){
          dist[nv]=dist[v]+c[e];
          pq.push(make_pair(dist[nv],nv));
        }
      }
    }
  }
  ans+=dist[0];
  cout<<ans<<endl;
}
0