結果

問題 No.1601 With Animals into Institute
ユーザー cureskolcureskol
提出日時 2021-07-10 14:09:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 627 ms / 3,000 ms
コード長 1,007 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 174,968 KB
実行使用メモリ 34,060 KB
最終ジャッジ日時 2023-09-14 19:16:08
合計ジャッジ時間 11,351 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 579 ms
33,840 KB
testcase_07 AC 581 ms
34,060 KB
testcase_08 AC 579 ms
33,928 KB
testcase_09 AC 582 ms
33,924 KB
testcase_10 AC 590 ms
33,964 KB
testcase_11 AC 591 ms
33,908 KB
testcase_12 AC 608 ms
33,804 KB
testcase_13 AC 627 ms
33,852 KB
testcase_14 AC 619 ms
33,980 KB
testcase_15 AC 588 ms
33,860 KB
testcase_16 AC 575 ms
33,900 KB
testcase_17 AC 565 ms
33,840 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 8 ms
4,380 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 9 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;
const long long LINF=1e18;
typedef pair<ll,ll> P;

int main(){
  int n,m;cin>>n>>m;
  vector<int> a(m),b(m),c(m),x(m);
  REP(i,m)cin>>a[i]>>b[i]>>c[i]>>x[i];

  vector<P> g[n*2];
  REP(i,m)a[i]--,b[i]--;
  REP(i,m){
    g[a[i]].push_back(P(b[i],c[i]));
    g[b[i]].push_back(P(a[i],c[i]));
    g[a[i]+n].push_back(P(b[i]+n,c[i]));
    g[b[i]+n].push_back(P(a[i]+n,c[i]));
    if(x[i])g[a[i]].push_back(P(b[i]+n,c[i]));
    if(x[i])g[b[i]].push_back(P(a[i]+n,c[i]));
  }

  vector<ll> d(n*2,LINF);
  d[n-1]=0;
  priority_queue<P,vector<P>,greater<P>> que;
  que.push(P(0,n-1));
  while(que.size()){
    P p=que.top();que.pop();
    ll idx=p.second,va=p.first;
    if(d[idx]<va)continue;
    for(P p:g[idx]){
      if(d[p.first]>va+p.second){
        d[p.first]=va+p.second;
        que.push(P(d[p.first],p.first));
      }
    }
  }
  REP(i,n-1)cout<<d[n+i]<<endl;
}
0