結果

問題 No.1473 おでぶなおばけさん
ユーザー rabimearabimea
提出日時 2023-03-13 09:04:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 3,623 ms
コンパイル使用メモリ 211,076 KB
実行使用メモリ 11,088 KB
最終ジャッジ日時 2023-10-18 10:55:12
合計ジャッジ時間 9,035 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,268 KB
testcase_01 AC 3 ms
7,268 KB
testcase_02 AC 66 ms
10,740 KB
testcase_03 AC 52 ms
9,848 KB
testcase_04 AC 36 ms
9,340 KB
testcase_05 AC 15 ms
7,880 KB
testcase_06 AC 55 ms
9,748 KB
testcase_07 AC 70 ms
11,080 KB
testcase_08 AC 73 ms
11,088 KB
testcase_09 AC 70 ms
11,080 KB
testcase_10 AC 40 ms
7,288 KB
testcase_11 AC 41 ms
7,284 KB
testcase_12 AC 41 ms
7,288 KB
testcase_13 AC 27 ms
7,272 KB
testcase_14 AC 21 ms
7,272 KB
testcase_15 AC 36 ms
7,272 KB
testcase_16 AC 39 ms
7,284 KB
testcase_17 AC 6 ms
7,272 KB
testcase_18 AC 8 ms
7,280 KB
testcase_19 AC 33 ms
7,792 KB
testcase_20 AC 44 ms
9,560 KB
testcase_21 AC 46 ms
8,404 KB
testcase_22 AC 52 ms
10,232 KB
testcase_23 AC 42 ms
10,168 KB
testcase_24 AC 43 ms
9,768 KB
testcase_25 AC 56 ms
10,084 KB
testcase_26 AC 59 ms
10,028 KB
testcase_27 AC 23 ms
8,136 KB
testcase_28 AC 66 ms
10,980 KB
testcase_29 AC 40 ms
8,548 KB
testcase_30 AC 46 ms
8,732 KB
testcase_31 AC 60 ms
10,940 KB
testcase_32 AC 48 ms
9,660 KB
testcase_33 AC 40 ms
9,428 KB
testcase_34 AC 23 ms
8,504 KB
testcase_35 AC 24 ms
8,044 KB
testcase_36 AC 42 ms
8,968 KB
testcase_37 AC 46 ms
9,960 KB
testcase_38 AC 12 ms
7,700 KB
testcase_39 AC 40 ms
7,288 KB
testcase_40 AC 40 ms
7,284 KB
testcase_41 AC 38 ms
7,272 KB
testcase_42 AC 37 ms
7,272 KB
testcase_43 AC 41 ms
9,436 KB
testcase_44 AC 42 ms
9,436 KB
testcase_45 AC 41 ms
9,436 KB
testcase_46 AC 48 ms
9,552 KB
testcase_47 AC 60 ms
10,036 KB
testcase_48 AC 54 ms
9,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 11;
vector <int> e[N];
struct edge {
	int u, v, w;
	bool operator <(const edge &e) const {
		return w > e.w;
	}
}a[N];

int p[N];
int find(int x) {
	if(p[x] == x) return x;
	return p[x] = find(p[x]);
}
int dis[N];

int main() {
	ios::sync_with_stdio(0);
	
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i ++) {
		cin >> a[i].u >> a[i].v >> a[i].w;
	}
	sort(a, a + m);
	
	iota(p, p + n + 1, 0);
	auto add = [&](int u, int v) {
		e[u].push_back(v);
		e[v].push_back(u);
		
		u = find(u);
		v = find(v);
		if(u != v)
			p[u] = v;
	};
	
	int p = 0, w = 0;
	while(find(1) != find(n)) {
		w = a[p].w;
		add(a[p].u, a[p].v);
		p ++;
	}
	while(p != m && a[p].w == w) {
		add(a[p].u, a[p].v);
		p ++;
	}
	
	fill(dis, dis + n + 1, 1e8);
	dis[1] = 0;
	queue <int> q; q.push(1);
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i : e[x]) {
			if(dis[i] > dis[x] + 1) {
				dis[i] = dis[x] + 1;
				q.push(i);
			}
		}
	}
	
	cout << w << ' ' << dis[n] << '\n';
}
0