結果

問題 No.807 umg tours
ユーザー QDSN
提出日時 2020-04-28 20:20:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,727 bytes
コンパイル時間 1,718 ms
コンパイル使用メモリ 179,592 KB
実行使用メモリ 60,576 KB
最終ジャッジ日時 2024-11-25 06:54:30
合計ジャッジ時間 14,847 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 21 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

// cout << "Case #" << test << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 2019
using namespace std;
using P = pair<ll, ll>;
vector<ll> Dijkstra_list(int n, int s, vector<vector<pair<ll, ll>>> &Edge) {
    vector<bool> visited(n, false); //確定済み
    vector<ll> d(n, __LONG_LONG_MAX__ / 3);
    // using P = pair<ll,ll>
    priority_queue<P, vector<P>, greater<P>> que; //頂点とsからの距離
    d[s] = 0;
    que.push(make_pair(0, s));
    while(!que.empty()) {
        auto now = que.top();
        que.pop();
        visited[now.second] = true;
        for(auto e : Edge[now.second]) {
            if(visited[e.second])
                continue;
            if(d[e.second] > d[now.second] + e.first) {
                d[e.second] = d[now.second] + e.first;
                que.push(make_pair(d[e.second], e.second));
            }
        }
    }
    return d;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<P>> edgetik(n * 2), edge(n);
    for(int i = 0; i < m; i++) {
        int u, v;
        ll c;
        cin >> u >> v >> c;
        u--, v--;
        edge[u].push_back(make_pair(c, v));
        edge[v].push_back(make_pair(c, u));
        edgetik[u * 2].push_back(make_pair(c, v * 2));
        edgetik[u * 2 + 1].push_back(make_pair(c, v * 2 + 1));
        edgetik[v * 2].push_back(make_pair(c, u * 2));
        edgetik[v * 2 + 1].push_back(make_pair(c, u * 2 + 1));
        edgetik[u * 2].push_back(make_pair(0, v * 2 + 1));
    }
    auto d = Dijkstra_list(n, 0, edge);
    auto dtik = Dijkstra_list(n * 2, 0, edgetik);
    for(int i = 0; i < n; i++) {
        cout << d[i] + min(dtik[2 * i], dtik[2 * i + 1]) << endl;
    }
}
0