# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
640710 | socpite | timeismoney (balkan11_timeismoney) | C++14 | 30 ms | 684 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;
#define oo 1000000000000000
#define f first
#define s second
vector<int> up;
int Find(int x){
if(up[x] < 0)return x;
else{
up[x]=Find(up[x]);
return up[x];
}
}
void Union(int a, int b){
a = Find(a);
b = Find(b);
up[b]=a;
}
long long n, m;
vector<pair<pair<int, int>,pair<long long, long long>>> E;
vector<pair<int, int>> ans;
long long tim = 0, money = 0, currpos, best;
bool cmp(pair<pair<int, int>,pair<long long, long long>> a, pair<pair<int, int>,pair<long long, long long>> b){
return a.s.f*b.s.s < a.s.s*b.s.f;
}
int main(){
cin >> n >> m;
E.resize(m);
up.assign(n, -1);
for(int i = 0; i < m; i++){
cin >> E[i].f.f >> E[i].f.s >> E[i].s.f >> E[i].s.s;
}
for(int j = 0; j < n-1; j++){
best = oo;
for(int i = 0; i < m; i++){
if(Find(E[i].f.f) == Find(E[i].f.s))continue;
else{
if(tim*E[i].s.s + money*E[i].s.f + E[i].s.s*E[i].s.f < best){
best = tim*E[i].s.s + money*E[i].s.f + E[i].s.s*E[i].s.f;
currpos = i;
}
}
}
tim += E[currpos].s.f;
money += E[currpos].s.s;
Union(E[currpos].f.f, E[currpos].f.s);
ans.push_back(E[currpos].f);
}
cout << tim << " " << money << endl;
for(int i =0; i < ans.size(); i++){
cout << ans[i].f << " " << ans[i].s << endl;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |