結果
| 問題 |
No.1473 おでぶなおばけさん
|
| コンテスト | |
| ユーザー |
homesentinel
|
| 提出日時 | 2021-04-09 22:16:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,617 bytes |
| コンパイル時間 | 1,524 ms |
| コンパイル使用メモリ | 140,412 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2024-06-25 05:48:57 |
| 合計ジャッジ時間 | 5,102 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 WA * 10 |
ソースコード
#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;
}
homesentinel