結果
| 問題 | No.1601 With Animals into Institute | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-12-06 10:21:29 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 254 ms / 3,000 ms | 
| コード長 | 1,016 bytes | 
| コンパイル時間 | 1,947 ms | 
| コンパイル使用メモリ | 182,692 KB | 
| 実行使用メモリ | 23,036 KB | 
| 最終ジャッジ日時 | 2024-10-13 02:39:30 | 
| 合計ジャッジ時間 | 8,676 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 36 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, u, v, w, c, x;
    ll d;
    cin >> n >> m;
    vector<vector<pair<int,int>>> g(2 * n);
    for(int i = 0; i < m; i++){
        cin >> u >> v >> w >> x;
        u--, v--;
        g[u].emplace_back(v + x * n, w);
        g[v].emplace_back(u + x * n, w);
        g[u + n].emplace_back(v + n, w);
        g[v + n].emplace_back(u + n, w);
    }
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
    vector<ll> dist(2 * n, 1ll << 60);
    dist[n - 1] = 0;
    pq.emplace(0, n - 1);
    while(!pq.empty()){
        tie(d, v) = pq.top();
        pq.pop();
        if(dist[v] > d)continue;
        for(auto &&p:g[v]){
            tie(u, w) = p;
            if(d + w >= dist[u])continue;
            dist[u] = d + w;
            pq.emplace(dist[u], u);
        }
    }
    for(int i = 0; i + 1 < n; i++){
        cout << dist[i + n] << '\n';
    }
}
            
            
            
        