結果

問題 No.1601 With Animals into Institute
ユーザー Nzt3Nzt3
提出日時 2022-07-02 00:08:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 3,000 ms
コード長 1,184 bytes
コンパイル時間 3,138 ms
コンパイル使用メモリ 207,248 KB
実行使用メモリ 23,236 KB
最終ジャッジ日時 2023-08-17 11:56:58
合計ジャッジ時間 11,139 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 220 ms
23,156 KB
testcase_07 AC 219 ms
23,056 KB
testcase_08 AC 221 ms
23,100 KB
testcase_09 AC 243 ms
23,192 KB
testcase_10 AC 225 ms
23,108 KB
testcase_11 AC 224 ms
23,144 KB
testcase_12 AC 225 ms
23,184 KB
testcase_13 AC 229 ms
23,236 KB
testcase_14 AC 220 ms
23,080 KB
testcase_15 AC 222 ms
23,044 KB
testcase_16 AC 221 ms
23,096 KB
testcase_17 AC 226 ms
23,096 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,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