# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
31759 | simotion | timeismoney (balkan11_timeismoney) | C++14 | 6 ms | 2488 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>
#define CNT 202
#define fi first
#define se second
using namespace std;
struct pd {
int p1,p2,t,c;
pd() {}
pd(int p1,int p2,int t,int c):p1(p1),p2(p2),t(t),c(c) {}
bool operator< (pd o) const {
return (t*c)<(o.t*o.c);
}
};
int n,m;
int t1,t2,t3,t4,lines;
int height[CNT],root[CNT];
int t_sum,c_sum;
vector<pd > kr;
vector<int> ans;
int find(int p) {
if(root[p]==p) return p;
else return root[p]=find(root[p]);
}
void uni(int a,int b) {
a=find(a),b=find(b);
if(height[a]>height[b]) swap(a,b);
if(height[a]==height[b]) height[b]++;
root[a]=b;
}
int main() {
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
height[i]=1,root[i]=i;
for(int i=0;i<m;i++) {
scanf("%d %d %d %d",&t1,&t2,&t3,&t4);
kr.push_back(pd(t1,t2,t3,t4));
}
sort(kr.begin(),kr.end());
for(int i=0;lines<n-1;i++) {
auto now=kr[i];
if(find(now.p1)!=find(now.p2)) {
uni(now.p1,now.p2);
lines++;
ans.push_back(i);
t_sum+=now.t,c_sum+=now.c;
}
}
printf("%d %d\n",t_sum,c_sum);
for(auto i=ans.begin();i!=ans.end();i++)
printf("%d %d\n",kr[*i].p1,kr[*i].p2);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |