結果

問題 No.2200 Weird Shortest Path
ユーザー warabi0906warabi0906
提出日時 2023-02-08 19:44:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 3,948 ms
コンパイル使用メモリ 235,404 KB
実行使用メモリ 8,532 KB
最終ジャッジ日時 2023-09-20 10:20:45
合計ジャッジ時間 12,130 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 63 ms
4,712 KB
testcase_18 AC 110 ms
6,032 KB
testcase_19 AC 193 ms
7,692 KB
testcase_20 AC 183 ms
8,012 KB
testcase_21 AC 71 ms
5,004 KB
testcase_22 AC 100 ms
5,652 KB
testcase_23 AC 195 ms
8,068 KB
testcase_24 AC 34 ms
4,380 KB
testcase_25 AC 186 ms
7,756 KB
testcase_26 AC 195 ms
8,100 KB
testcase_27 AC 67 ms
5,076 KB
testcase_28 AC 144 ms
6,700 KB
testcase_29 AC 196 ms
7,896 KB
testcase_30 AC 197 ms
8,012 KB
testcase_31 AC 120 ms
6,240 KB
testcase_32 AC 198 ms
8,020 KB
testcase_33 AC 198 ms
7,980 KB
testcase_34 AC 197 ms
8,468 KB
testcase_35 AC 198 ms
8,152 KB
testcase_36 AC 197 ms
8,204 KB
testcase_37 AC 197 ms
8,180 KB
testcase_38 AC 197 ms
8,344 KB
testcase_39 AC 100 ms
5,648 KB
testcase_40 AC 153 ms
8,080 KB
testcase_41 AC 87 ms
5,656 KB
testcase_42 AC 139 ms
8,532 KB
testcase_43 AC 209 ms
8,088 KB
testcase_44 AC 208 ms
8,284 KB
testcase_45 AC 209 ms
8,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include "atcoder/all"
#define debug cout << "OK" << endl;
template<typename T>
inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }
inline int Code(char c) {
	if ('A' <= c and c <= 'Z')return (int)(c - 'A');
	if ('a' <= c and c <= 'z')return (int)(c - 'a');
	if ('0' <= c and c <= '9')return (int)(c - '0');
	assert(false);
}
using namespace std;
using namespace atcoder;
#define int long long
constexpr int MOD = 998244353;
constexpr int INF = (1LL << 63);
using minit = modint998244353;

template<typename T>
ostream& operator << (ostream& st, const vector<T>& v) {
	for (const T value : v) {
		st << value << " ";
	}
	return st;
}
template<typename T>
istream& operator >> (istream& st, vector<T>& v) {
	for (T& value : v) {
		st >> value;
	}
	return st;
}

//

//

void solve() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, pair<int, int>>> E(M);
	for (int e = 0; e < M; e++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		E[e] = { w,{u,v} };
	}
	sort(E.begin(), E.end());
	dsu d(N);
	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (d.same(E[i].second.first, E[i].second.second))continue;
		ans += (int)d.size(E[i].second.first) * (int)d.size(E[i].second.second) * E[i].first;
		d.merge(E[i].second.first, E[i].second.second);
	}
	cout << ans << endl;
}
signed main() {
	int T = 1;
	// cin >> T;
	for (int i = 0; i < T; i++)
		solve();
	return 0;
}

/*
* わらびのコードこーどすぺーす
 (σ・∀・)σゲッツ!!
*/
0