# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886247 | Rafi22 | timeismoney (balkan11_timeismoney) | C++14 | 1746 ms | 1564 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
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
int mod=1000000007;
int mod1=998244353;
const int N=207,M=10007;
int U[M],V[M],X[M],Y[M];
bool cmp(pair<int,int>L,pair<int,int>R)
{
return L.st*R.nd<R.st*L.nd;
}
vector<int>W;
int n;
int r[N];
int Find(int v)
{
if(r[v]==v) return v;
return r[v]=Find(r[v]);
}
vector<pair<int,int>>ans,act;
int sX,sY,bX,bY,res=2*inf;
void Union(int u,int v,int i)
{
int uu=Find(u),vv=Find(v);
if(uu==vv) return ;
r[uu]=vv;
act.pb({u,v});
sX+=X[i];
sY+=Y[i];
}
void calc()
{
for(int i=0;i<n;i++) r[i]=i;
act.clear();
sX=0;
sY=0;
for(auto i:W)
{
Union(U[i],V[i],i);
if(sX*sY>=res) break;
}
if(sX*sY<res)
{
res=sX*sY;
ans=act;
bX=sX;
bY=sY;
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m;
cin>>n>>m;
vector<pair<int,int>>ord;
for(int i=0;i<m;i++)
{
cin>>U[i]>>V[i]>>X[i]>>Y[i];
ord.pb({X[i],i});
}
sort(all(ord));
for(auto [c,x]:ord) W.pb(x);
vector<pair<int,int>>F;
F.pb({0,1});
for(int a=1;a<=255;a++) for(int b=1;b<=255;b++) if(__gcd(a,b)==1) F.pb({a,b});
sort(all(F),cmp);
calc();
for(auto [a,b]:F)
{
for(int i=0;i<m;i++)
{
int j=i;
while(j>0&&a*X[W[j]]+b*Y[W[j]]<a*X[W[j-1]]+b*Y[W[j-1]])
{
swap(W[j],W[j-1]);
j--;
}
}
calc();
}
cout<<bX<<" "<<bY<<endl;
for(auto [x,y]:ans) cout<<x<<" "<<y<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |