結果

問題 No.1601 With Animals into Institute
ユーザー chocorusk
提出日時 2021-07-10 14:08:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 728 ms / 3,000 ms
コード長 1,610 bytes
コンパイル時間 4,073 ms
コンパイル使用メモリ 187,280 KB
最終ジャッジ日時 2025-01-23 00:04:31
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
ll d[2][100010];
int n, m;
vector<P> g[100010];
int a[200010], b[200010];
ll c[200010];
int x[200010];
const ll INF=1e18;
int main()
{
    cin>>n>>m;
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i]>>c[i]>>x[i];
        a[i]--; b[i]--;
        g[a[i]].push_back({b[i], i});
        g[b[i]].push_back({a[i], i});
    }
    fill(d[0], d[0]+n, INF);
    fill(d[1], d[1]+n, INF);
    d[0][n-1]=0;
    using Pl=pair<ll, P>;
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    que.push({0, {n-1, 0}});
    while(!que.empty()){
        auto p=que.top(); que.pop();
        int x1=p.second.first;
        int t=p.second.second;
        if(p.first>d[t][x1]) continue;
        for(auto q:g[x1]){
            int y1=q.first;
            int i=q.second;
            if(d[x[i]|t][y1]>d[t][x1]+c[i]){
                d[x[i]|t][y1]=d[t][x1]+c[i];
                que.push({d[x[i]|t][y1], {y1, (x[i]|t)}});
            }
        }
    }
    for(int i=0; i<n-1; i++){
        cout<<d[1][i]<<endl;
    }
    return 0;
}
0