# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
268017 | stefantaga | timeismoney (balkan11_timeismoney) | C++14 | 19 ms | 640 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;
struct wow
{
int x,y,bani,timp;
}v[10005];
bool compare (wow a,wow b)
{
return a.bani*a.timp<b.bani*b.timp;
}
int tata[205],sol[2005],q,rang[205],sumbani,sumtimp;
int parinte (int x)
{
if (tata[x]!=x)
{
return parinte(tata[x]);
}
return x;
}
void uneste (int x,int y)
{
x=parinte(x);
y=parinte(y);
if (rang[x]<rang[y])
{
tata[x]=y;
}
else
if (rang[x]>rang[y])
{
tata[y]=x;
}
else
{
tata[x]=y;
rang[y]++;
}
}
int n,m,i;
int main()
{
#ifdef HOME
ifstream cin("timeismoney.in");
ofstream cout("timeismoney.out");
#endif // HOME
cin>>n>>m;
for (i=1;i<=m;i++)
{
cin>>v[i].x>>v[i].y>>v[i].bani>>v[i].timp;
}
sort (v+1,v+m+1,compare);
for (i=1;i<=n;i++)
{
tata[i]=i;
rang[i]=1;
}
for (i=1;i<=m;i++)
{
if (parinte(v[i].x)!=parinte(v[i].y))
{
uneste(v[i].x,v[i].y);
sumbani=sumbani+v[i].bani;
sumtimp=sumtimp+v[i].timp;
sol[++q]=i;
}
}
cout<<sumbani<<" "<<sumtimp<<'\n';
for (i=1;i<=q;i++)
{
cout<<v[i].x<<" "<<v[i].y<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |