Tags » MST

HRW: How Boosted US Defense Funds Could Support Military Rape Survivors

Check out HRW’s dispatch (that I drafted with Counsel Hershel Eisenberger) on how the increased Department of Defense budget could support survivors of military sexual trauma by allowing for more funds to be allotted to military discharge review boards. 50 more words

Mystery Science Theater 3000: The Return, is seriously hilarious!

Merely seven days ago the cult classic series MST3K got a brand new series on the streaming service Netflix. The series is 14 episodes long and is considered the eleventh season of the original series. 320 more words

Entertainment

What "love" feels like

Love feels wonderful. It makes you feel like you deserve all the good things in your life despite of your shortcomings. Loves feels inviting. It makes you vulnerable to the people around you that cares and allows you to trust again. 764 more words

Life

Thuật toán Kruskal tìm cây khung nhỏ nhì

Code C++:
Độ phức tạp: O(VE)

#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <utility>
#include <cmath>
#include <set>
using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int oo = 1e10;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ii> edge;

int n, m, lab;
vector<edge> edges, mst_edges;

int root(int u) {
    if (lab[u] < 0) return u;
    return lab[u] = root(lab[u]);
}

void merge(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return;
    if (lab[u] > lab[v]) swap(u, v);
    lab[u] += lab[v];
    lab[v] = u;
}

ll scan_edges(int _u = 0, int _v = 0) {
    memset(lab, -1, sizeof lab);
    
    ll min_cost = 0;
    for(auto e : edges) {
        int u = e.se.fi;
        int v = e.se.se;
        ll w = e.fi;
        if (u == _u && v == _v) continue;
        if (root(u) != root(v)) {
            merge(u, v);
            min_cost += w;
            if (_u == _v) mst_edges.pb(e);
        }
    }
    
    set<int> roots;
    for(int u = 1; u <= n; u++) roots.insert(root(u));
    if (roots.size() != 1) return oo;
    return min_cost;
}

int main() {
    
    // reset
    edges.clear(); mst_edges.clear();
    memset(lab, -1, sizeof lab);
    
    // input
    cin >> n >> m;
    for(int i = 1; i <= m; i++) {
        int u, v; ll w;
        cin >> u >> v >> w;
        edges.pb(mp(w, mp(u, v)));
    }
    
    // modify Kruskal
    sort(edges.begin(), edges.end());
    
    cout << "MST: " << scan_edges() << '\n';
    ll mincost2 = oo;
    for(edge e : mst_edges)
        mincost2 = min(mincost2, scan_edges(e.se.fi, e.se.se));
    cout << "MST2: " << mincost2;
    
    return 0;
}
… 6 more words
Algorithm