제출 #1142227

#제출 시각아이디문제언어결과실행 시간메모리
1142227lyricclamptimeismoney (balkan11_timeismoney)C++20
0 / 100
2 ms776 KiB
#include<bits/stdc++.h> #define endl '\n' #define pb push_back using ll = long long; using namespace std; struct something{ ll size, boss, total; }; vector<something> thing, edge; ll findboss(ll x) { if(x == thing[x].boss) return x; return thing[x].boss = findboss(thing[x].boss); } void merge(ll x, ll y) { x = findboss(x); y = findboss(y); thing[y].size += thing[x].size; thing[x].size = thing[y].size; if(thing[x].size < thing[y].size) swap(x, y); thing[x].boss = y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); ll n, m; cin >> n >> m; for(int i = 0; i < m; i++) { ll a, b, c; cin >> a >> b >> c >> c; edge.pb({c, a + 1, b + 1}); } thing.resize(n + 1, {1}); for(int i = 1; i <= n; i++) thing[i].boss = i; vector<pair<ll, ll>> ans; ll t = 0, c = 0; for(int i = 0; i < m; i++) { ll x = edge[i].boss, y = edge[i].total; if(findboss(x) != findboss(y)) { merge(x, y); t += edge[i].size; c += edge[i].size; ans.pb({x, y}); } } cout << t << " " << c << endl; for(auto i: ans) cout << i.first << " " << i.second << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...