結果

問題 No.1473 おでぶなおばけさん
ユーザー tkmst201tkmst201
提出日時 2021-06-13 09:27:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,101 bytes
コンパイル時間 2,441 ms
コンパイル使用メモリ 213,288 KB
実行使用メモリ 11,164 KB
最終ジャッジ日時 2023-08-23 11:24:47
合計ジャッジ時間 8,964 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 72 ms
10,468 KB
testcase_03 AC 53 ms
8,940 KB
testcase_04 AC 37 ms
7,300 KB
testcase_05 AC 14 ms
4,416 KB
testcase_06 AC 57 ms
9,016 KB
testcase_07 AC 73 ms
11,056 KB
testcase_08 AC 77 ms
11,164 KB
testcase_09 AC 75 ms
10,948 KB
testcase_10 AC 39 ms
4,660 KB
testcase_11 AC 39 ms
4,688 KB
testcase_12 AC 38 ms
4,724 KB
testcase_13 AC 25 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 34 ms
4,472 KB
testcase_16 AC 37 ms
4,804 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 32 ms
5,276 KB
testcase_20 AC 45 ms
8,044 KB
testcase_21 AC 46 ms
6,592 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 67 ms
10,880 KB
testcase_29 WA -
testcase_30 AC 45 ms
7,324 KB
testcase_31 AC 60 ms
10,824 KB
testcase_32 AC 46 ms
9,152 KB
testcase_33 AC 40 ms
7,924 KB
testcase_34 AC 21 ms
5,904 KB
testcase_35 AC 23 ms
5,196 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 39 ms
4,736 KB
testcase_40 AC 38 ms
4,816 KB
testcase_41 AC 40 ms
4,840 KB
testcase_42 AC 37 ms
4,672 KB
testcase_43 AC 40 ms
8,052 KB
testcase_44 AC 39 ms
8,252 KB
testcase_45 AC 39 ms
8,300 KB
testcase_46 AC 57 ms
7,856 KB
testcase_47 AC 73 ms
8,940 KB
testcase_48 AC 60 ms
8,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

/**
 * @brief https://tkmst201.github.io/Library/DataStructure/UnionFind.hpp
 */
struct UnionFind {
	using size_type = std::size_t;
	
private:
	size_type n;
	std::vector<int> dat;
	
public:
	explicit UnionFind(size_type n) : n(n), dat(n, -1) {}
	
	size_type size(size_type x) noexcept {
		assert(x < n);
		return -dat[find(x)];
	}
	
	size_type find(size_type x) noexcept {
		assert(x < n);
		if (dat[x] < 0) return x;
		return dat[x] = find(dat[x]);
	}
	
	void unite(size_type x, size_type y) noexcept {
		assert(x < n);
		assert(y < n);
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (dat[x] < dat[y]) std::swap(x, y);
		dat[y] += dat[x];
		dat[x] = y;
	}
	
	bool issame(size_type x, size_type y) noexcept {
		assert(x < n);
		assert(y < n);
		return find(x) == find(y);
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g(N);
	UnionFind uf(N);
	vector<int> S(M), T(M), D(M);
	REP(i, M) scanf("%d %d %d", &S[i], &T[i], &D[i]), --S[i], --T[i];
	vector<int> ord(M);
	iota(ALL(ord), 0);
	sort(ALL(ord), [&](int i, int j) { return D[i] > D[j]; });
	int mx = 0;
	for (int i : ord) {
		uf.unite(S[i], T[i]);
		g[S[i]].emplace_back(T[i]);
		g[T[i]].emplace_back(S[i]);
		mx = D[i];
		if (uf.issame(0, N - 1)) break;
	}
	
	queue<int> que;
	vector<int> dist(N, INF);
	que.emplace(0);
	dist[0] = 0;
	while (!que.empty()) {
		auto u = que.front(); que.pop();
		for (int v : g[u]) if (chmin(dist[v], dist[u] + 1)) que.emplace(v);
	}
	cout << mx << " " << dist[N - 1] << endl;
}
0