# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
741730 | abcvuitunggio | timeismoney (balkan11_timeismoney) | C++17 | 436 ms | 780 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 int long long
using namespace std;
struct edge{
int u,v,t,c;
}e[10001];
int n,m,p[201],sz[201],mn=1e18;
vector <edge> v,res;
pair <int, int> q;
int f(int i){
return (p[i]==i?i:p[i]=f(p[i]));
}
int unite(int i, int j){
i=f(i);
j=f(j);
if (i==j)
return 0;
if (sz[i]<sz[j])
swap(i,j);
p[j]=i;
sz[i]+=sz[j];
return 1;
}
int A,B;
pair <int, int> calc(int a, int b){
int time=0,cost=0;
A=a,B=b;
for (int i=0;i<n;i++){
p[i]=i;
sz[i]=1;
}
sort(e+1,e+m+1,[](edge x, edge y){return x.t*A+x.c*B<y.t*A+y.c*B;});
v.clear();
for (int i=1;i<=m;i++){
int y=unite(e[i].u,e[i].v);
time+=y*e[i].t;
cost+=y*e[i].c;
if (y)
v.push_back(e[i]);
}
if (mn>time*cost){
mn=time*cost;
q={time,cost};
res=v;
}
return {time,cost};
}
void g(pair <int, int> a, pair <int, int> b){
auto c=calc(a.second-b.second,b.first-a.first);
if ((c.second-a.second)*(b.first-a.first)==(b.second-a.second)*(c.first-a.first))
return;
g(a,c);
g(c,b);
}
int32_t main(){
ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
cin >> n >> m;
for (int i=1;i<=m;i++)
cin >> e[i].u >> e[i].v >> e[i].t >> e[i].c;
g(calc(1,0),calc(0,1));
cout << q.first << ' ' << q.second << '\n';
for (auto e:res)
cout << e.u << ' ' << e.v << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |