結果

問題 No.807 umg tours
ユーザー hagyu_ayahagyu_aya
提出日時 2019-03-22 22:11:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,425 bytes
コンパイル時間 2,314 ms
コンパイル使用メモリ 156,292 KB
実行使用メモリ 17,724 KB
最終ジャッジ日時 2023-08-15 11:59:46
合計ジャッジ時間 10,525 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,108 KB
testcase_01 AC 3 ms
5,712 KB
testcase_02 AC 3 ms
5,780 KB
testcase_03 AC 4 ms
5,744 KB
testcase_04 AC 4 ms
5,972 KB
testcase_05 AC 3 ms
5,800 KB
testcase_06 AC 3 ms
5,728 KB
testcase_07 AC 3 ms
5,744 KB
testcase_08 AC 3 ms
5,740 KB
testcase_09 AC 3 ms
5,680 KB
testcase_10 AC 3 ms
5,720 KB
testcase_11 AC 120 ms
12,544 KB
testcase_12 AC 127 ms
11,912 KB
testcase_13 AC 188 ms
13,592 KB
testcase_14 AC 72 ms
9,144 KB
testcase_15 AC 51 ms
8,212 KB
testcase_16 AC 172 ms
14,076 KB
testcase_17 AC 246 ms
17,560 KB
testcase_18 AC 235 ms
17,724 KB
testcase_19 AC 205 ms
15,096 KB
testcase_20 AC 109 ms
10,992 KB
testcase_21 AC 120 ms
11,184 KB
testcase_22 AC 44 ms
7,984 KB
testcase_23 AC 33 ms
7,472 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

struct Edge{
    int to;
    int cost;
};
vector<Edge> g[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }

    /*

    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    vector<ll> d(n, LLINF);
    d[0] = 0;
    que.push({ll(0), 0});
    
    while(!que.empty()){
        ll c = que.top().first;
        int v = que.top().second;
        que.pop();
        
        for(auto && e : g[v]){
            if(d[e.to] > c + e.cost){
                d[e.to] = c + e.cost;
                que.push({d[e.to], e.to});
            }
        }
    }

    */
    
    priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<pair<ll, pii>>> que2;
    vector<ll> d2(n, LLINF);
    vector<ll> d3(n, LLINF);
    d2[0] = 0; // 未使用
    d3[0] = 0; // 使用済み
    que2.push({0, {0, 0}});

    while(!que2.empty()){
        ll c = que2.top().first;
        int v = que2.top().second.first;
        bool used = bool(que2.top().second.second);
        que2.pop();

        for(auto && e : g[v]){
            if(used){
                if(d3[e.to] > c + e.cost){
                    d3[e.to] = c + e.cost;
                    que2.push({d3[e.to], {e.to, 1}});
                }
            }
            else{
                if(d2[e.to] > c + e.cost){
                    d2[e.to] = c + e.cost;
                    que2.push({d2[e.to], {e.to, 0}});
                }
                if(d3[e.to] > c){
                    d3[e.to] = c;
                    que2.push({d3[e.to], {e.to, 1}});
                }
            }
        }
    }
    
    cout << "0\n";
    for(int i = 1; i < n; ++i){
        cout << d2[i] + d3[i] << "\n";
    }
    
    
    return 0;
}
0