結果

問題 No.1473 おでぶなおばけさん
ユーザー homesentinelhomesentinel
提出日時 2021-04-09 22:14:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,588 bytes
コンパイル時間 1,603 ms
コンパイル使用メモリ 140,500 KB
実行使用メモリ 11,632 KB
最終ジャッジ日時 2023-09-07 11:38:43
合計ジャッジ時間 5,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 23 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 33 ms
4,632 KB
testcase_42 AC 33 ms
4,852 KB
testcase_43 AC 37 ms
8,652 KB
testcase_44 AC 37 ms
8,516 KB
testcase_45 AC 37 ms
8,608 KB
testcase_46 AC 46 ms
8,912 KB
testcase_47 AC 56 ms
9,868 KB
testcase_48 AC 51 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit

struct UnionFind {
    vector<int> par, sz;

    UnionFind(int n) : par(n), sz(n, 1) {
        for (int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (sz[x] < sz[y]) swap(x, y);
        par[y] = x;
        sz[x] += sz[y];
        sz[y] = 0;
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return sz[root(x)];
    }
};


template<typename T>
class graph {
    struct edge {
        int src, to;
        T cost;
    };

public:
    int n;
    vector<vector<edge>> edges;

    graph(int n_) : n(n_), edges(n_) {
    }

    void add_edge(int src, int to, T cost) {
        edges[src].push_back({src, to, cost});
    }
};

template<typename T>
pair<vector<T>, vector<int>> dijkstra(const graph<T> &g, int s, T inf) {
    vector<T> d(g.edges.size(), inf);
    vector<int> p(g.edges.size());

    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;

    que.emplace(0, s);
    d[s] = 0;
    p[s] = -1;

    while (!que.empty()) {
        T cost;
        int v;
        tie(cost, v) = que.top();
        que.pop();

        if (d[v] < cost) continue;
        for (const auto &e : g.edges[v]) {
            T ncost = cost + e.cost;
            int nv = e.to;
            if (ncost < d[nv]) {
                d[nv] = ncost;
                p[nv] = v;
                que.emplace(ncost, nv);
            }
        }
    }

    return make_pair(d, p);
}

void solve() {
    int n, m;
    cin >> n >> m;

    vector<tuple<int, int, ll>> E(m);
    REP(i, m) {
        int s, t;
        ll d;
        cin >> s >> t >> d;
        s--, t--;
        E[i] = make_tuple(s, t, d);
    }

    sort(ALL(E), [](auto l, auto r) {
        return get<2>(l) > get<2>(r);
    });

    UnionFind uf(n);
    graph<int> g(n);

    int max_weight = 0;
    for (int i = 0; i < m; ++i) {
        if (uf.issame(0, n - 1)) {
            break;
        }
        max_weight = get<2>(E[i]);
        int s, t;
        ll d;
        tie(s, t, d) = E[i];
        uf.merge(s, t);
        g.add_edge(s, t, 1);
    }

    auto dist = dijkstra(g, 0, INF).first;
    int ans = dist[n - 1];

    cout << max_weight << " " << ans << endl;


}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}
0