結果

問題 No.1473 おでぶなおばけさん
ユーザー rodearodea
提出日時 2021-04-11 14:58:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 2,088 bytes
コンパイル時間 1,384 ms
コンパイル使用メモリ 124,328 KB
実行使用メモリ 10,052 KB
最終ジャッジ日時 2023-09-09 17:21:39
合計ジャッジ時間 10,161 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 290 ms
9,732 KB
testcase_03 AC 121 ms
8,820 KB
testcase_04 AC 196 ms
6,688 KB
testcase_05 AC 76 ms
4,448 KB
testcase_06 AC 249 ms
9,192 KB
testcase_07 AC 193 ms
9,904 KB
testcase_08 AC 363 ms
9,816 KB
testcase_09 AC 164 ms
10,052 KB
testcase_10 AC 38 ms
6,156 KB
testcase_11 AC 41 ms
7,768 KB
testcase_12 AC 37 ms
6,972 KB
testcase_13 AC 25 ms
5,352 KB
testcase_14 AC 18 ms
4,616 KB
testcase_15 AC 34 ms
6,468 KB
testcase_16 AC 34 ms
5,992 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 58 ms
6,652 KB
testcase_20 AC 93 ms
8,308 KB
testcase_21 AC 123 ms
8,136 KB
testcase_22 AC 54 ms
9,156 KB
testcase_23 AC 45 ms
8,284 KB
testcase_24 AC 44 ms
8,172 KB
testcase_25 AC 486 ms
9,072 KB
testcase_26 AC 468 ms
9,356 KB
testcase_27 AC 81 ms
5,356 KB
testcase_28 AC 314 ms
9,792 KB
testcase_29 AC 137 ms
8,404 KB
testcase_30 AC 213 ms
9,120 KB
testcase_31 AC 154 ms
9,860 KB
testcase_32 AC 146 ms
9,396 KB
testcase_33 AC 115 ms
8,116 KB
testcase_34 AC 74 ms
5,840 KB
testcase_35 AC 46 ms
6,036 KB
testcase_36 AC 127 ms
7,380 KB
testcase_37 AC 235 ms
7,868 KB
testcase_38 AC 30 ms
4,380 KB
testcase_39 AC 36 ms
5,880 KB
testcase_40 AC 35 ms
5,892 KB
testcase_41 AC 42 ms
5,588 KB
testcase_42 AC 40 ms
5,576 KB
testcase_43 AC 95 ms
8,004 KB
testcase_44 AC 94 ms
8,104 KB
testcase_45 AC 94 ms
8,004 KB
testcase_46 AC 60 ms
7,476 KB
testcase_47 AC 75 ms
8,728 KB
testcase_48 AC 76 ms
8,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

vector<int> dijkstra(int s, int w, vector<vector<T>> &G){
    int n = G.size();
    vector<int> dist(n, inf);
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv; tie(ccost, cv) = que.top(); que.pop();
        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv, ncost, nw; tie(nv, ncost, nw) = nxt;
            
            if(w <= nw && ccost + ncost < dist[nv]){
                dist[nv] = ccost + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

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

    int n, m; cin>>n>>m;
    vector<vector<T>> G(n);
    for(int i=0; i<m; i++){
        int s, t, d; cin>>s>>t>>d; s--, t--;
        G[s].emplace_back(t, 1, d);
        G[t].emplace_back(s, 1, d);
    }

    int ok = 1, ng = inf + 1;
    while(ng - ok > 1){
        int mid = (ok + ng) / 2;
        auto dist = dijkstra(0, mid, G);
        if(dist[n - 1] != inf) ok = mid;
        else ng = mid;
    }

    auto ans = dijkstra(0, ok, G);

    cout << ok << " " << ans[n - 1] << endl;

    return 0;
}
0