Submission #152325

#TimeUsernameProblemLanguageResultExecution timeMemory
152325JovanK26timeismoney (balkan11_timeismoney)C++14
45 / 100
9 ms504 KiB
#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)

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:77:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<mst.size();i++)
                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...