結果
| 問題 |
No.1601 With Animals into Institute
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-10 14:12:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 666 ms / 3,000 ms |
| コード長 | 793 bytes |
| コンパイル時間 | 3,459 ms |
| コンパイル使用メモリ | 204,096 KB |
| 最終ジャッジ日時 | 2025-01-23 00:06:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include<bits/stdc++.h>
#define int long long
using namespace std;
using P=tuple<int,int,int>;
constexpr int INF=1e18;
struct edge{int to,cost,animal;};
bool chmin(int&a,int b){return a>b?a=b,true:false;}
vector<edge> G[1<<20];
int dist[1<<20][2];
signed main(){
int N,M; cin>>N>>M;
for(int i=0;i<M;i++){
int a,b,c,d; cin>>a>>b>>c>>d;
G[--a].push_back({--b,c,d});
G[b].push_back({a,c,d});
}
fill(dist[0],dist[N],INF); dist[N-1][0]=0;
priority_queue<P,vector<P>,greater<P>> Q; Q.push({0,N-1,0});
while(!Q.empty()){
auto[c,v,a]=Q.top(); Q.pop();
if(dist[v][a]<c)continue;
for(edge e:G[v])if(chmin(dist[e.to][a|e.animal],c+e.cost))Q.push({c+e.cost,e.to,a|e.animal});
}
for(int i=0;i<N-1;i++)cout<<dist[i][1]<<endl;
}