結果

問題 No.1473 おでぶなおばけさん
ユーザー Be11T_Be11T_
提出日時 2021-04-10 13:35:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 2,535 bytes
コンパイル時間 4,595 ms
コンパイル使用メモリ 267,404 KB
実行使用メモリ 11,732 KB
最終ジャッジ日時 2023-09-08 09:41:38
合計ジャッジ時間 13,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 244 ms
11,500 KB
testcase_03 AC 113 ms
10,116 KB
testcase_04 AC 152 ms
7,908 KB
testcase_05 AC 56 ms
5,012 KB
testcase_06 AC 232 ms
11,024 KB
testcase_07 AC 192 ms
11,412 KB
testcase_08 AC 362 ms
11,464 KB
testcase_09 AC 170 ms
11,420 KB
testcase_10 AC 39 ms
7,420 KB
testcase_11 AC 43 ms
8,884 KB
testcase_12 AC 40 ms
8,432 KB
testcase_13 AC 24 ms
6,160 KB
testcase_14 AC 19 ms
5,304 KB
testcase_15 AC 35 ms
7,612 KB
testcase_16 AC 36 ms
6,684 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 54 ms
7,856 KB
testcase_20 AC 89 ms
9,668 KB
testcase_21 AC 109 ms
9,444 KB
testcase_22 AC 72 ms
10,816 KB
testcase_23 AC 61 ms
9,772 KB
testcase_24 AC 56 ms
9,724 KB
testcase_25 AC 75 ms
10,672 KB
testcase_26 AC 81 ms
10,892 KB
testcase_27 AC 24 ms
6,132 KB
testcase_28 AC 275 ms
11,732 KB
testcase_29 AC 115 ms
9,676 KB
testcase_30 AC 184 ms
10,552 KB
testcase_31 AC 153 ms
11,608 KB
testcase_32 AC 125 ms
11,216 KB
testcase_33 AC 102 ms
9,520 KB
testcase_34 AC 54 ms
6,620 KB
testcase_35 AC 44 ms
6,872 KB
testcase_36 AC 89 ms
8,404 KB
testcase_37 AC 225 ms
9,192 KB
testcase_38 AC 19 ms
4,560 KB
testcase_39 AC 37 ms
6,848 KB
testcase_40 AC 37 ms
6,744 KB
testcase_41 AC 36 ms
6,444 KB
testcase_42 AC 36 ms
6,448 KB
testcase_43 AC 60 ms
10,004 KB
testcase_44 AC 61 ms
9,956 KB
testcase_45 AC 60 ms
10,008 KB
testcase_46 AC 69 ms
8,872 KB
testcase_47 AC 92 ms
10,212 KB
testcase_48 AC 88 ms
9,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, m, n) for(ll i = m; i <= n; i++)
#define rrep(i, m, n) for(ll i = m; i >= n; i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SZ(a) ((ll)(a).size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, 1, -1 };
const int inf = 1e9 + 1;
const ll INF = 1e18 + 1;
const double pi = acos(-1);

using Graph = vector<vector<int>>;
Graph G;

typedef atcoder::modint1000000007 mint;
//typedef atcoder::modint998244353 mint;
//typedef modint mint;
struct Edge {
    int to;
    ll cost;
    Edge(int t, ll c) : to(t), cost(c) {

    }

};
struct Node {
    int node;
    ll cost;
    Node(int n, ll c) : node(n), cost(c) {

    }
    bool operator<(const Node& n)const {
        return cost > n.cost;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;

    vector<ll> d(n);
    vector<vector<Edge>> edge(n);
    priority_queue<Node> q;

    rep(i, m) {
        ll a, b, c; cin >> a >> b >> c;
        a--, b--;
        edge[a].emplace_back(Edge(b, c));
        edge[b].emplace_back(Edge(a, c));
    }

    ll W = 0, D = n + 1;

    ll l = 0, h = 2e9;
    while (h - l >= 1) {
        int mid = (l + h) / 2;
        rep(i, n) d[i] = INF;
        d[0] = 0;
        
        q.push(Node(0, 0));

        while (!q.empty()) {
            auto p = q.top(); q.pop();
            if (d[p.node] < p.cost) continue;
            for (auto e : edge[p.node]) {
                if (e.cost < mid) continue;
                if (d[e.to] > p.cost + 1) {
                    d[e.to] = p.cost + 1;
                    q.push(Node(e.to, d[e.to]));
                }
            }
        }

        if (d[n - 1] == INF) {
            h = mid;
        }
        else {
            l = mid + 1;
        }
    }
    rep(i, n) d[i] = INF;
    d[0] = 0;

    q.push(Node(0, 0));
    W = h - 1;

    while (!q.empty()) {
        auto p = q.top(); q.pop();
        if (d[p.node] < p.cost) continue;
        for (auto e : edge[p.node]) {
            if (e.cost < W) continue;
            if (d[e.to] > p.cost + 1) {
                d[e.to] = p.cost + 1;
                q.push(Node(e.to, d[e.to]));
            }
        }
    }
    cout << W << " " << d[n - 1] << endl;
}
0