# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152325 | JovanK26 | timeismoney (balkan11_timeismoney) | C++14 | 9 ms | 504 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;
int prt[201];
int sz[201];
struct edge
{
int a;
int b;
int t;
int c;
};
bool cmp(edge i,edge j)
{
return i.t<j.t;
}
void init()
{
for(int i=0;i<201;i++)
{
prt[i]=i;
sz[i]=1;
}
}
int findd(int x)
{
while(x!=prt[x])
{
prt[x]=prt[prt[x]];
x=prt[x];
}
return x;
}
void unionn(int x,int y)
{
x=findd(x);
y=findd(y);
if(sz[x]<sz[y])swap(x,y);
prt[y]=x;
sz[x]+=sz[y];
}
int rez1=0;
int rez2=0;
vector<pair<int,int> >mst;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin >> n >> m;
vector<edge> edg(m);
int a,b,t,c;
for(int i=0;i<m;i++)
{
cin >> a >> b >> t >> c;
edge temp;
temp.a=a;
temp.b=b;
temp.t=t;
temp.c=c;
edg[i]=temp;
}
sort(edg.begin(),edg.end(),cmp);
init();
for(int i=0;i<m;i++)
{
if(findd(edg[i].a)!=findd(edg[i].b))
{
rez1+=edg[i].t;
rez2+=edg[i].c;
mst.push_back(make_pair(edg[i].a,edg[i].b));
unionn(edg[i].a,edg[i].b);
}
}
cout << rez1<<' '<<rez2<<'\n';
for(int i=0;i<mst.size();i++)
{
cout << mst[i].first << ' '<<mst[i].second<<'\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |