結果

問題 No.807 umg tours
ユーザー T1610T1610
提出日時 2019-03-22 21:49:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 4,000 ms
コード長 2,011 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 174,280 KB
実行使用メモリ 22,404 KB
最終ジャッジ日時 2023-08-15 11:53:41
合計ジャッジ時間 5,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,352 KB
testcase_01 AC 4 ms
7,368 KB
testcase_02 AC 4 ms
7,320 KB
testcase_03 AC 3 ms
7,296 KB
testcase_04 AC 3 ms
7,264 KB
testcase_05 AC 4 ms
7,576 KB
testcase_06 AC 3 ms
7,284 KB
testcase_07 AC 4 ms
7,316 KB
testcase_08 AC 3 ms
7,232 KB
testcase_09 AC 3 ms
7,260 KB
testcase_10 AC 3 ms
7,284 KB
testcase_11 AC 107 ms
17,704 KB
testcase_12 AC 104 ms
14,688 KB
testcase_13 AC 142 ms
17,344 KB
testcase_14 AC 61 ms
11,356 KB
testcase_15 AC 49 ms
10,464 KB
testcase_16 AC 144 ms
18,016 KB
testcase_17 AC 188 ms
22,404 KB
testcase_18 AC 187 ms
21,824 KB
testcase_19 AC 189 ms
18,988 KB
testcase_20 AC 91 ms
12,432 KB
testcase_21 AC 95 ms
12,808 KB
testcase_22 AC 40 ms
9,720 KB
testcase_23 AC 31 ms
9,180 KB
testcase_24 AC 94 ms
18,576 KB
testcase_25 AC 188 ms
21,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define int long long
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 1e5+10;
struct Edge{ int to, cost; };
vector<Edge> es[MAX_N];
ll d[MAX_N*2];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        es[a].pb({b, c});
        es[b].pb({a, c});
    }
    rep(i, MAX_N*2) d[i] = 1e18;
    int root = 0;
    auto dijkstra = [&] () {
        typedef pair<int, int> P; //dist, from
        priority_queue<P, vector<P>, greater<P> > q;
        d[root] = 0LL;
        d[root+1] = 0LL;
        q.push({0LL, root});
        while (!q.empty()) {
            auto p = q.top(); q.pop();
            int prv = p.se;
            auto cost = p.fi;
            if (d[prv] < p.fi) continue;
            int cur = prv / 2;
            int flag = prv&1LL;
            for (auto& e : es[cur]) {
                int to = e.to;
                if(d[to*2+flag] > d[prv] + e.cost) {
                    d[to*2+flag] = d[prv] + e.cost;
                    q.push({d[to*2+flag],to*2+flag});
                }
                if(flag == 0 && d[to*2+1] > d[prv]) {
                    d[to*2+1] = d[prv];
                    q.push({d[to*2+1], to*2+1});
                }
            }
        }
    };
    dijkstra();
    rep(i, n) {
        cout << d[i*2] + d[i*2+1] << '\n';
    }
    // rep(i, n) {
    //     cout << d[i*2] << " " << d[i*2+1] << endl;
    // }
    return 0;
}
0