Submission #1141791

#TimeUsernameProblemLanguageResultExecution timeMemory
1141791qqusayytimeismoney (balkan11_timeismoney)C++20
40 / 100
2 ms776 KiB
#include "bits/stdc++.h"
#define P ' '
#define L '\n'
#define F first
#define S size()
#define PB push_back
#define B begin()
#define E end()
#define SS second
#define PBB pop_back()
using ll = long long;
using namespace std;

struct edge {
    ll a, b, weight;
    bool operator< (edge x) const {
        return weight < x.weight;
    }
};
struct DSU{
    ll parent[202];
    
    void create(ll x) {
        parent[x] = x;
    }
    ll find(ll x) {
        if (x == parent[x]) return x;
        return parent[x] = find(parent[x]);
    }
    bool unite(ll a, ll b) {
        a = find(a);
        b = find(b);
        if (a != b) {
            parent[b] = a;
            return 1;
        }
        return 0;
    }
    
};



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);

    ll n, m;
    cin >> n >> m;
    DSU t;
    vector<pair<ll, ll>> ans;
    vector<edge> edges;
    for (int i = 0; i < m; i++) {
        ll x, y, C, T;
        cin >> x >> y >> T >> C;
        edges.PB({x, y, T});
        t.create(x);
        t.create(y);
    }
    sort(edges.B, edges.E);
    
    ll cost = 0;
    for (edge e : edges) {
        if (t.unite(e.a, e.b)) {
            ans.PB({e.a, e.b});
            cost += e.weight;
        }
    }
    cout << cost << P << cost << L;
    for (auto [f, s] : ans) cout << f << P << s << L;
}
#Verdict Execution timeMemoryGrader output
Fetching results...