# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029161 | lucri | timeismoney (balkan11_timeismoney) | C++17 | 8 ms | 2908 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;
long long t[210],u[10010],v[10010],ti[10010],mo[10010],n,m,vmax=2000000000,st,sm,p1,p2;
long long sumt,summ;
struct muchii{long long u,v,val,valt,valm;}a[100010];
long long tata(long long n)
{
if(t[n]==n)return n;
return t[n]=tata(t[n]);
}
bool comp(muchii a,muchii b)
{
if(a.val!=b.val)return a.val<b.val;
if(a.u!=b.u)return a.u<b.u;
if(a.v!=b.v)return a.v<b.v;
return a.valt<b.valt;
}
void calculeaza(long long v1,long long v2)
{
for(long long i=0;i<n;++i)
t[i]=i;
for(long long i=1;i<=m;++i)
a[i]={u[i],v[i],ti[i]*v1+mo[i]*v2,ti[i],mo[i]};
sumt=summ=0;
sort(a+1,a+m+1,comp);
for(long long i=1;i<=m;++i)
{
if(tata(a[i].u)!=tata(a[i].v))
{
t[t[a[i].u]]=t[a[i].v];
sumt+=a[i].valt;
summ+=a[i].valm;
}
}
}
void scrie(long long v1,long long v2)
{
for(long long i=0;i<n;++i)
t[i]=i;
for(long long i=1;i<=m;++i)
a[i]={u[i],v[i],ti[i]*v1+mo[i]*v2,ti[i],mo[i]};
sort(a+1,a+m+1,comp);
for(long long i=1;i<=m;++i)
{
if(tata(a[i].u)!=tata(a[i].v))
{
t[t[a[i].u]]=t[a[i].v];
cout<<a[i].u<<' '<<a[i].v<<'\n';
}
}
}
int main()
{
cin>>n>>m;
for(long long i=1;i<=m;++i)
cin>>u[i]>>v[i]>>ti[i]>>mo[i];
calculeaza(1,1);
cout<<st<<' '<<sm<<'\n';
scrie(1,1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |