結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 83 ms
12,612 KB
testcase_03 AC 53 ms
10,520 KB
testcase_04 AC 41 ms
8,664 KB
testcase_05 AC 14 ms
4,980 KB
testcase_06 AC 61 ms
10,396 KB
testcase_07 AC 78 ms
13,192 KB
testcase_08 AC 102 ms
13,332 KB
testcase_09 AC 82 ms
13,332 KB
testcase_10 AC 37 ms
4,552 KB
testcase_11 AC 37 ms
4,888 KB
testcase_12 AC 37 ms
4,548 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 32 ms
4,696 KB
testcase_16 AC 35 ms
4,592 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 30 ms
5,736 KB
testcase_20 AC 44 ms
9,808 KB
testcase_21 AC 47 ms
7,460 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 73 ms
13,004 KB
testcase_29 WA -
testcase_30 AC 45 ms
8,064 KB
testcase_31 AC 87 ms
13,348 KB
testcase_32 AC 49 ms
10,388 KB
testcase_33 AC 45 ms
9,584 KB
testcase_34 AC 26 ms
6,728 KB
testcase_35 AC 23 ms
5,768 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 36 ms
4,656 KB
testcase_40 AC 36 ms
4,700 KB
testcase_41 AC 33 ms
4,792 KB
testcase_42 AC 34 ms
4,588 KB
testcase_43 AC 43 ms
9,584 KB
testcase_44 AC 42 ms
9,492 KB
testcase_45 AC 42 ms
9,672 KB
testcase_46 AC 53 ms
9,868 KB
testcase_47 AC 64 ms
11,556 KB
testcase_48 AC 56 ms
10,688 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);
        g.add_edge(t, s, 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