# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
712316 | study | timeismoney (balkan11_timeismoney) | C++17 | 6 ms | 724 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 201;
int comp[N],siz[N];
int sum=0;
vector<pair<int,int>> ans;
int getComp(int node){
if (comp[node] != node) comp[node] = getComp(comp[node]);
return comp[node];
}
void merge(int a, int b, int cost){
a = getComp(a);
b = getComp(b);
if (a != b){
if (siz[a] < siz[b]) swap(a,b);
ans.emplace_back(a,b);
cout << a << ' ' << b << ' ' << cost << endl;
siz[a] += siz[b];
comp[a] = b;
sum += cost;
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> n >> m;
vector<tuple<int,int,int>> v;
for (int i=0; i<m; ++i){
int x,y,t,c;
cin >> x >> y >> t >> c;
v.emplace_back(t,x,y);
}
for (int i=0; i<n; ++i){
siz[i] = 1;
comp[i] = i;
}
sort(v.begin(),v.end());
for (auto [t,x,y]:v){
merge(x,y,t);
}
cout << sum << ' ' << sum << '\n';
for (auto i:ans) cout << i.first << ' ' << i.second << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |