結果

問題 No.807 umg tours
ユーザー T1610T1610
提出日時 2019-03-22 21:49:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 4,000 ms
コード長 2,011 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 176,864 KB
実行使用メモリ 21,100 KB
最終ジャッジ日時 2024-05-02 23:19:22
合計ジャッジ時間 5,097 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,296 KB
testcase_01 AC 4 ms
7,168 KB
testcase_02 AC 3 ms
7,368 KB
testcase_03 AC 3 ms
7,296 KB
testcase_04 AC 3 ms
7,368 KB
testcase_05 AC 3 ms
7,236 KB
testcase_06 AC 4 ms
7,296 KB
testcase_07 AC 3 ms
7,296 KB
testcase_08 AC 3 ms
7,236 KB
testcase_09 AC 3 ms
7,296 KB
testcase_10 AC 3 ms
7,236 KB
testcase_11 AC 104 ms
17,884 KB
testcase_12 AC 100 ms
14,816 KB
testcase_13 AC 142 ms
17,520 KB
testcase_14 AC 59 ms
11,664 KB
testcase_15 AC 44 ms
10,624 KB
testcase_16 AC 143 ms
18,056 KB
testcase_17 AC 185 ms
21,064 KB
testcase_18 AC 181 ms
21,100 KB
testcase_19 AC 178 ms
19,216 KB
testcase_20 AC 88 ms
12,480 KB
testcase_21 AC 96 ms
12,544 KB
testcase_22 AC 39 ms
9,640 KB
testcase_23 AC 29 ms
9,216 KB
testcase_24 AC 89 ms
17,560 KB
testcase_25 AC 188 ms
21,028 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