結果

問題 No.1473 おでぶなおばけさん
ユーザー oliverx3oliverx3
提出日時 2021-04-09 23:23:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 7,349 bytes
コンパイル時間 4,654 ms
コンパイル使用メモリ 274,124 KB
実行使用メモリ 11,656 KB
最終ジャッジ日時 2023-09-07 13:13:12
合計ジャッジ時間 12,297 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 184 ms
11,216 KB
testcase_03 AC 145 ms
10,368 KB
testcase_04 AC 113 ms
7,532 KB
testcase_05 AC 44 ms
4,664 KB
testcase_06 AC 201 ms
10,688 KB
testcase_07 AC 183 ms
11,476 KB
testcase_08 AC 228 ms
11,656 KB
testcase_09 AC 174 ms
11,596 KB
testcase_10 AC 98 ms
7,520 KB
testcase_11 AC 108 ms
8,904 KB
testcase_12 AC 96 ms
8,104 KB
testcase_13 AC 54 ms
6,224 KB
testcase_14 AC 43 ms
5,340 KB
testcase_15 AC 88 ms
7,580 KB
testcase_16 AC 89 ms
6,896 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 13 ms
4,380 KB
testcase_19 AC 84 ms
7,544 KB
testcase_20 AC 104 ms
9,484 KB
testcase_21 AC 125 ms
9,360 KB
testcase_22 AC 103 ms
10,316 KB
testcase_23 AC 83 ms
9,572 KB
testcase_24 AC 83 ms
9,460 KB
testcase_25 AC 218 ms
10,476 KB
testcase_26 AC 230 ms
10,472 KB
testcase_27 AC 62 ms
5,916 KB
testcase_28 AC 209 ms
11,412 KB
testcase_29 AC 130 ms
9,272 KB
testcase_30 AC 170 ms
10,192 KB
testcase_31 AC 153 ms
11,408 KB
testcase_32 AC 147 ms
11,036 KB
testcase_33 AC 117 ms
9,404 KB
testcase_34 AC 62 ms
6,472 KB
testcase_35 AC 64 ms
6,564 KB
testcase_36 AC 106 ms
8,336 KB
testcase_37 AC 134 ms
9,088 KB
testcase_38 AC 24 ms
4,452 KB
testcase_39 AC 92 ms
6,844 KB
testcase_40 AC 90 ms
6,904 KB
testcase_41 AC 77 ms
6,580 KB
testcase_42 AC 77 ms
6,384 KB
testcase_43 AC 96 ms
9,184 KB
testcase_44 AC 96 ms
9,196 KB
testcase_45 AC 96 ms
9,192 KB
testcase_46 AC 118 ms
8,860 KB
testcase_47 AC 149 ms
10,112 KB
testcase_48 AC 142 ms
9,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
// using namespace atcoder;
#endif
#define int long long

#pragma region header

#pragma region alias

using lint = long long;
using ll = long long;
using P = std::pair<int,int>;
template<class T> using prique = std::priority_queue<T,std::vector<T>,std::greater<T>>;

#pragma endregion

#pragma region macros

#define rep(i, n) for(int i = 0;i<(int)(n);i++)
#define REP(i, m, n) for(int i = (m);i<(int)(n);i++)
#define drep(i, n) for(int i = (n)-1;i>=0;i--)
#define DREP(i, m, n) for(int i = (m)-1;i>=(int)(n);i--)
#define all(v) (v).begin(),(v).end()
#define reall(v) (v).rbegin(),(v).rend()

template<class T, class U>
bool chmax(T& a,const U b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T, class U>
bool chmin(T& a,const U b) {
    if(a>b) {
        a = b;
        return true;
    }
    return false;
}

std::map<int,int> prime_div(int n) {
    std::map<int,int> mp;
    if(~n&1) while(~n&1) n>>=1,mp[2]++;
    for(int i = 3;i<=std::sqrt(n);i+=2) {
        if(n%i==0) {
            while(n%i==0) {
                n/=i;
                mp[i]++;
            }
        }
    }
    if(n!=1) mp[n]++;
    return mp;
}

bool is_flag(const int &bit, const int &k) { return (bit >> k)&1; }

#pragma endregion

#pragma region constant

constexpr long long inf = 1LL << 61;
constexpr long double eps = 1e-10;
constexpr long double pi = 3.141592653589793238;
constexpr int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
constexpr int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
constexpr long long mod = 1e9+7;
constexpr long long MOD = 998244353;

#pragma endregion

#pragma region inout

template<class T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& v) {
    for(int i = 0; i < (int)(v.size()); i++) {
        stream << v[i];
        if(i != (int)(v.size()) - 1) stream << ' ';
    }
    return stream;
}

template<typename Itr>
inline void print(const Itr& begin, const Itr& end, bool endline = true, const char* BEGIN = "{", const char* mid = ", ", const char* END = "}") {
    if(begin == end) return;
    std::cout << BEGIN << *begin;
    for(Itr itr = begin+1; itr < end; itr++) std::cout << mid << *itr;
    std::cout << END;
    if(endline) std::endl(std::cout);
    return;
}

template<class T>
std::istream& operator>>(std::istream& stream, std::vector<T>& v) {
    for(T& p:v) stream >> p;
    return stream;
}

template<typename Itr>
inline void input(Itr begin, Itr end) {
    for(Itr& itr = begin; itr < end; itr++) std::cin >> *itr;
    return;
}

template<class T, class U>
std::ostream& operator<<(std::ostream& stream, const std::pair<T,U>& pair) {
    return stream << pair.first << ' ' << pair.second;
}

template<class T, class U>
inline void print(const std::pair<T,U>& pair,const bool endline = true, const char* begin = "(", const char* mid = ", ", const char* end = ")") {
    std::cout << begin << pair.first << mid << pair.second << end;
    if(endline) std::endl(std::cout);
    else std::cout << ' ';
    return;
}

template<class T, class U>
std::istream& operator>>(std::istream& stream, std::pair<T,U>& pair) {
    return stream >> pair.first >> pair.second;
}

template<class T, class U>
inline void input(std::pair<T,U>& pair, const bool first = true, const bool second = true) {
    if(first) std::cin >> pair.first;
    if(second) std::cin >> pair.second;
}

#pragma endregion

#pragma region DEBUG

#ifdef _DEBUG
template<class T>
inline void _debug_view(const T& x) noexcept {
    std::cout << x;
    return;
}

template<class T, class U>
inline void _debug_view(const std::pair<T,U>& p) noexcept {
    std::cout << "(";
    _debug_view(p.first);
    std::cout << ", ";
    _debug_view(p.second);
    std::cout << ")";
    return;
}

template<class T>
inline void _debug_view(const std::vector<T>& v) noexcept {
    std::cout << "{";
    for(int i = 0;i<v.size();i++) {
        _debug_view(v[i]);
        std::cout << (i+1 == v.size() ? "" : ", ");
    }
    std::cout << "}";
    return;
}

template<class T, class U>
inline void _debug_view(const std::map<T,U>& mp) noexcept {
    std::cout << "{";
    for(auto itr = mp.begin(); itr != mp.end(); itr++) {
        _debug_view(*itr);
        if(std::next(itr) != mp.end()) std::cout << ", ";
    }
    std::cout << "}";
    return;
}

template<class T> 
inline void _debug_view(const std::set<T>& st) noexcept {
    std::cout << "{";
    for(auto itr = st.begin(); itr != st.end(); itr++) {
        _debug_view(*itr);
        if(std::next(itr) != st.end()) std::cout << ", ";
    }
    std::cout << "}";
    return;
}

#define overload5(_1,_2,_3,_4,_5,name,...) name

#define _debug1(a) {\
    do {\
        std::cout << #a << ": ";\
        _debug_view(a);\
        std::endl(std::cout);\
    }while(0);\
}

#define _debug2(a,b) {\
    do {\
        std::cout << #a << ": ";\
        _debug_view(a);\
        std::cout << ", " << #b << ": ";\
        _debug_view(b);\
        std::endl(std::cout);\
    }while(0);\
}

#define _debug3(a,b,c) {\
    do {\
        std::cout << #a << ": ";\
        _debug_view(a);\
        std::cout << ", " << #b << ": ";\
        _debug_view(b);\
        std::cout << ", " << #c << ": ";\
        _debug_view(c);\
        std::endl(std::cout);\
    }while(0);\
}

#define _debug4(a,b,c,d) {\
    do {\
        std::cout << #a << ": ";\
        _debug_view(a);\
        std::cout << ", " << #b << ": ";\
        _debug_view(b);\
        std::cout << ", " << #c << ": ";\
        _debug_view(c);\
        std::cout << ", " << #d << ": ";\
        _debug_view(d);\
        std::endl(std::cout);\
    }while(0);\
}

#define _debug5(a,b,c,d,e) {\
    do {\
        std::cout << #a << ": ";\
        _debug_view(a);\
        std::cout << ", " << #b << ": ";\
        _debug_view(b);\
        std::cout << ", " << #c << ": ";\
        _debug_view(c);\
        std::cout << ", " << #d << ": ";\
        _debug_view(d);\
        std::cout << ", " << #e << ": ";\
        _debug_view(e);\
        std::endl(std::cout);\
    }while(0);\
}

#define debug(...) overload5(__VA_ARGS__,_debug5,_debug4,_debug3,_debug2,_debug1,)(__VA_ARGS__)

#else
#define debug(...)
#endif

#pragma endregion

#pragma endregion

signed main(void) {
    int n,m;
    std::cin >> n >> m;
    struct edge {
        int to,cost;
    };
    std::vector<std::vector<edge>> G(n);
    rep(i, m) {
        int a,b,cost;
        std::cin >> a >> b >> cost;
        a--,b--;
        G[a].push_back({b,cost});
        G[b].push_back({a,cost});
    }
    auto bfs = [&](int weight)->int{
        std::vector<int> dist(n);
        std::fill(all(dist),-1);
        dist[0] = 0;
        std::queue<int> que;
        que.push(0);
        while(!que.empty()) {
            int node = que.front();que.pop();
            for(const auto &e:G[node]) {
                if(dist[e.to]!=-1) continue;
                if(weight>e.cost) continue;
                dist[e.to] = dist[node]+1;
                que.push(e.to);
            }
        }
        return dist[n-1];
    };
    int ok = 0,ng = 1'000'000'010;
    while(ng-ok>1) {
        int mid = (ok+ng)/2;
        if(bfs(mid)==-1) ng = mid;
        else ok = mid;
    }
    const int ans = bfs(ok);
    std::cout << ok << ' ' << ans << std::endl;
    return 0;
}
0