# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723345 | groshi | timeismoney (balkan11_timeismoney) | C++17 | 1040 ms | 1108 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;
int t[20000][4];
int MAX=1000;
int ojc[3000];
int find_u(int x)
{
if(ojc[x]==x)
return x;
return ojc[x]=find_u(ojc[x]);
}
void union_f(int x,int y)
{
x=find_u(x);
y=find_u(y);
ojc[x]=y;
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,m,x,y,s,c;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>x>>y>>s>>c;
t[i][0]=x;
t[i][1]=y;
t[i][2]=s;
t[i][3]=c;
}
vector<pair<int,int> > Q;
vector<pair<int,int> > wypisz;
int S=1e9;
int T=1e9;
for(int i=0;i<=MAX;i++)
{
for(int j=0;j<n;j++)
ojc[j]=j;
vector<pair<int,int> > mam;
Q.clear();
for(int j=1;j<=m;j++)
Q.push_back({i*t[j][2]+(MAX-i)*t[j][3],j});
sort(Q.begin(),Q.end());
int wynik=0;
s=0,c=0;
for(int i=0;i<Q.size();i++)
{
int kto=Q[i].second;
if(find_u(t[kto][0])==find_u(t[kto][1]))
continue;
s+=t[kto][3];
c+=t[kto][2];
union_f(t[kto][0],t[kto][1]);
mam.push_back({t[kto][0],t[kto][1]});
}
if(s*c<S*T)
{
S=s;
T=c;
wypisz=mam;
}
}
cout<<T<<" "<<S<<"\n";
for(int i=0;i<wypisz.size();i++)
cout<<wypisz[i].first<<" "<<wypisz[i].second<<"\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |