結果

問題 No.1601 With Animals into Institute
ユーザー Nzt3Nzt3
提出日時 2022-07-02 00:08:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 3,000 ms
コード長 1,184 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 209,484 KB
実行使用メモリ 23,380 KB
最終ジャッジ日時 2024-05-04 18:40:24
合計ジャッジ時間 8,513 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 219 ms
23,252 KB
testcase_07 AC 205 ms
23,224 KB
testcase_08 AC 213 ms
23,364 KB
testcase_09 AC 217 ms
23,200 KB
testcase_10 AC 215 ms
23,224 KB
testcase_11 AC 216 ms
23,360 KB
testcase_12 AC 212 ms
23,364 KB
testcase_13 AC 216 ms
23,380 KB
testcase_14 AC 215 ms
23,332 KB
testcase_15 AC 218 ms
23,352 KB
testcase_16 AC 220 ms
23,376 KB
testcase_17 AC 217 ms
23,336 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<vector<array<long long,3>>>G(N);
  for(int i=0;i<M;i++){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    --a,--b;
    G[a].push_back({b,c,d});
    G[b].push_back({a,c,d});
  }
  vector<long long>dist(N,1e18),dist1(N,1e18);
  dist[N-1]=0;
  priority_queue<array<long long,3>,vector<array<long long,3>>,greater<array<long long,3>>>pq;
  pq.push({0,N-1,0});
  while(pq.size()){
    long long v=pq.top()[1],d=pq.top()[0],a=pq.top()[2];
    pq.pop();
    if(a==1){
      if(dist1[v]<d)continue;
      for(auto i:G[v]){
        if(dist1[i[0]]>d+i[1]){
          dist1[i[0]]=d+i[1];
          pq.push({d+i[1],i[0],1});
        }
      }
    }else{
      if(dist[v]<d)continue;
      for(auto i:G[v]){
        if(i[2]){
          if(dist1[i[0]]>d+i[1]){
            dist1[i[0]]=d+i[1];
            pq.push({d+i[1],i[0],1});
          }
        }else{
          if(dist[i[0]]>d+i[1]){
            dist[i[0]]=d+i[1];
            pq.push({d+i[1],i[0],0});
          }
        }
      }
    }
  }
  for(int i=0;i<N-1;i++){
    cout<<dist1[i]<<'\n';
  }
}
0