# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
845035 | alexdd | timeismoney (balkan11_timeismoney) | C++17 | 3 ms | 604 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 n,m;
pair<pair<int,int>,pair<int,int>> edges[10005];
int father[300];
int siz[300];
int gas(int x)
{
if(x!=father[x])
father[x]=gas(father[x]);
return father[x];
}
void unite(int x, int y)
{
x = gas(x);
y = gas(y);
if(x==y)
return;
if(siz[x]<siz[y])
swap(x,y);
father[y]=x;
siz[x]+=siz[y];
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++)
father[i]=i,siz[i]=1;
for(int i=0;i<m;i++)
{
cin>>edges[i].second.first>>edges[i].second.second>>edges[i].first.first>>edges[i].first.second;
}
sort(edges,edges+m);
int sum0=0,sum1=0;
vector<pair<int,int>> sol;
for(int i=0;i<m;i++)
{
if(gas(edges[i].second.first)!=gas(edges[i].second.second))
{
unite(edges[i].second.first,edges[i].second.second);
sol.push_back(edges[i].second);
sum0+=edges[i].first.first;
sum1+=edges[i].first.second;
}
}
cout<<sum0<<" "<<sum1<<"\n";
for(int i=0;i<sol.size();i++)
cout<<sol[i].first<<" "<<sol[i].second<<"\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |