結果
問題 | No.2200 Weird Shortest Path |
ユーザー |
|
提出日時 | 2023-02-08 19:26:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,604 bytes |
コンパイル時間 | 4,267 ms |
コンパイル使用メモリ | 237,244 KB |
実行使用メモリ | 8,484 KB |
最終ジャッジ日時 | 2024-07-06 05:40:24 |
合計ジャッジ時間 | 12,898 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 WA * 1 |
ソースコード
#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 += d.size(E[i].second.first) * 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; } /* * わらびのコードこーどすぺーす (σ・∀・)σゲッツ!! */