結果

問題 No.1601 With Animals into Institute
ユーザー umezoumezo
提出日時 2021-07-10 14:10:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 497 ms / 3,000 ms
コード長 1,322 bytes
コンパイル時間 2,051 ms
コンパイル使用メモリ 210,640 KB
実行使用メモリ 30,820 KB
最終ジャッジ日時 2023-09-14 19:17:01
合計ジャッジ時間 10,188 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 462 ms
30,784 KB
testcase_07 AC 480 ms
30,792 KB
testcase_08 AC 494 ms
30,820 KB
testcase_09 AC 497 ms
30,736 KB
testcase_10 AC 491 ms
30,672 KB
testcase_11 AC 477 ms
30,668 KB
testcase_12 AC 466 ms
30,792 KB
testcase_13 AC 472 ms
30,720 KB
testcase_14 AC 469 ms
30,760 KB
testcase_15 AC 469 ms
30,684 KB
testcase_16 AC 462 ms
30,736 KB
testcase_17 AC 472 ms
30,656 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 6 ms
4,376 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const ll INF=1LL<<60;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

template<class T> bool chmin(T& a,T b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}

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

  int n,m;
  cin>>n>>m;
  
  Graph G(2*n);
  rep(i,m){
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    a--,b--;
    G[a].push_back(Edge(b,c));
    G[b].push_back(Edge(a,c));
    G[a+n].push_back(Edge(b+n,c));
    G[b+n].push_back(Edge(a+n,c));
    if(x==1){
      G[a].push_back(Edge(b+n,c));
      G[b].push_back(Edge(a+n,c));
      G[a+n].push_back(Edge(b,c));
      G[b+n].push_back(Edge(a,c));
    }
  }
  
  vector<ll> dist(2*n,INF);
  int s=2*n-1;
  dist[s]=0;
  
  priority_queue<pli,vector<pli>,greater<pli>> que;
  que.push({dist[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;
    
    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  rep(i,n-1) cout<<dist[i]<<endl;
  
  return 0;
}
0