結果

問題 No.1473 おでぶなおばけさん
ユーザー jutamajutama
提出日時 2021-04-15 12:05:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 3,422 bytes
コンパイル時間 3,599 ms
コンパイル使用メモリ 177,780 KB
実行使用メモリ 11,948 KB
最終ジャッジ日時 2023-09-14 03:21:46
合計ジャッジ時間 7,641 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 68 ms
11,296 KB
testcase_03 AC 43 ms
9,164 KB
testcase_04 AC 35 ms
7,840 KB
testcase_05 AC 12 ms
4,900 KB
testcase_06 AC 51 ms
9,160 KB
testcase_07 AC 63 ms
11,948 KB
testcase_08 AC 70 ms
11,816 KB
testcase_09 AC 63 ms
11,764 KB
testcase_10 AC 33 ms
4,636 KB
testcase_11 AC 33 ms
4,636 KB
testcase_12 AC 31 ms
4,876 KB
testcase_13 AC 20 ms
4,380 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 29 ms
4,724 KB
testcase_16 AC 31 ms
4,624 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 28 ms
5,156 KB
testcase_20 AC 38 ms
8,596 KB
testcase_21 AC 46 ms
7,140 KB
testcase_22 AC 54 ms
11,020 KB
testcase_23 AC 47 ms
9,804 KB
testcase_24 AC 48 ms
9,772 KB
testcase_25 AC 60 ms
10,768 KB
testcase_26 AC 62 ms
11,180 KB
testcase_27 AC 20 ms
6,416 KB
testcase_28 AC 60 ms
11,496 KB
testcase_29 AC 37 ms
6,908 KB
testcase_30 AC 43 ms
7,672 KB
testcase_31 AC 64 ms
11,780 KB
testcase_32 AC 40 ms
9,112 KB
testcase_33 AC 41 ms
8,624 KB
testcase_34 AC 25 ms
6,432 KB
testcase_35 AC 21 ms
5,416 KB
testcase_36 AC 42 ms
8,676 KB
testcase_37 AC 47 ms
9,428 KB
testcase_38 AC 9 ms
4,548 KB
testcase_39 AC 31 ms
4,628 KB
testcase_40 AC 31 ms
4,624 KB
testcase_41 AC 30 ms
4,740 KB
testcase_42 AC 29 ms
4,720 KB
testcase_43 AC 41 ms
9,620 KB
testcase_44 AC 42 ms
9,632 KB
testcase_45 AC 40 ms
9,576 KB
testcase_46 AC 42 ms
9,220 KB
testcase_47 AC 53 ms
10,484 KB
testcase_48 AC 46 ms
9,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bitset>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using namespace atcoder;

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

void input() {
    
    
}

template <class Cost> struct graph_l {

    public :
    graph_l(int n) : _n(n), _graph(n), _dist(n, 0) {}

    void add (int from, int to, Cost cost){
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        _graph[from].push_back(_edge{(unsigned int)from, (unsigned int)to, cost});
    }
    void add_bi (int from, int to, Cost cost){
        add(from, to, cost);
        add(to, from, cost);
    }

    Cost get_dist (int v) {
        assert(0 <= v && v < _n);
        return _dist[v];
    }

    void dijkstra (int s) {
        assert(0 <= s && s < _n);
        for (int i = 0 ; i < _n ; ++i) { _dist[i] = DIST_INF; }

        auto edge_compare = [] (_edge e1, _edge e2) {
            if (e1.cost != e2.cost) return e1.cost > e2.cost;
            else if (e1.to != e2.to) return e1.to > e2.to;
            else return e1.from > e2.from;
        };
        priority_queue<_edge, vector<_edge>, function<bool(_edge, _edge)>> edge_que(edge_compare);
        for (auto e : _graph[s]) {
            edge_que.push(_edge{e.from, e.to, e.cost});
            if(_dist[e.to] > e.cost) _dist[e.to] = e.cost;
        }
        while (!edge_que.empty()) {
            _edge p = edge_que.top(); edge_que.pop();
            unsigned int v = p.to;
            if (_dist[v] < p.cost) continue;
            for (auto e : _graph[v]) {
                auto next_cost = e.cost + _dist[v];
                if (_dist[e.to] <= next_cost) continue;
                _dist[e.to] = next_cost;
                edge_que.push(_edge{e.from, e.to, _dist[e.to]});
            }
        }
    }

private:
    int _n;
    const Cost DIST_INF = numeric_limits<Cost>::max();

    struct _edge {
        unsigned int from;
        unsigned int to;
        Cost cost;
    };
    std::vector<std::vector<_edge>> _graph;
    std::vector<Cost> _dist;
};


void solve() {

    using pii = pair<int, int>;
    int N, M; cin >> N >> M;
    vector<int> S(M), T(M);
    vector<pii> D(M);
    for(int i = 0; i < M; i++) {
        int s, t, d; cin >> s >> t >> d;
        s--; t--;
        S[i] = s;
        T[i] = t;
        D[i] = {d, i};
    }
    
    auto compare = [](pii a, pii b) -> bool {
        if(a.first != b.first) return a.first > b.first;
        else return a.second < b.second;
    };
    sort(D.begin(), D.end(), compare);
    
    int w = 0;
    dsu UF(N);
    graph_l<int> G(N);
    for(int i = 0; i < M; i++) {
        int wi = D[i].first;
        int ni = D[i].second;
        
        UF.merge(S[ni], T[ni]);
        if(w > 0 && w > wi) break;
        if(w == 0 && UF.same(0, N-1)) {
            w = wi;
        }
        
        G.add_bi(S[ni], T[ni], 1);
    }
    G.dijkstra(0);
    
    cout << w << " " << G.get_dist(N-1) << endl;
    
    
}

//* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *//

int main() {
    
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
    std::cin.tie(0);
    ios::sync_with_stdio(false);
    
    input();
    solve();
    
    return 0;
}
0