Submission #640727

#TimeUsernameProblemLanguageResultExecution timeMemory
640727socpitetimeismoney (balkan11_timeismoney)C++14
60 / 100
35 ms588 KiB
#include<bits/stdc++.h> using namespace std; #define oo 1000000000000000 #define f first #define s second vector<int> up; int Find(int x){ if(up[x] < 0)return x; else{ up[x]=Find(up[x]); return up[x]; } } void Union(int a, int b){ a = Find(a); b = Find(b); up[b]=a; } long long n, m; vector<pair<pair<int, int>,pair<long long, long long>>> E; vector<pair<int, int>> ans; long long tim = 0, money = 0, currpos, best; bool cmp(pair<pair<int, int>,pair<long long, long long>> a, pair<pair<int, int>,pair<long long, long long>> b){ return a.s.f*b.s.s < a.s.s*b.s.f; } int main(){ cin >> n >> m; E.resize(m); up.assign(n, -1); for(int i = 0; i < m; i++){ cin >> E[i].f.f >> E[i].f.s >> E[i].s.f >> E[i].s.s; } sort(E.begin(), E.end(), cmp); reverse(E.begin(), E.end()); for(int j = 0; j < n-1; j++){ best = oo; for(int i = 0; i < m; i++){ if(Find(E[i].f.f) == Find(E[i].f.s))continue; else{ if(tim*E[i].s.s + money*E[i].s.f + E[i].s.s*E[i].s.f < best){ best = tim*E[i].s.s + money*E[i].s.f + E[i].s.s*E[i].s.f; currpos = i; } } } tim += E[currpos].s.f; money += E[currpos].s.s; Union(E[currpos].f.f, E[currpos].f.s); ans.push_back(E[currpos].f); } cout << tim << " " << money << endl; for(int i =0; i < ans.size(); i++){ cout << ans[i].f << " " << ans[i].s << endl; } }

Compilation message (stderr)

timeismoney.cpp: In function 'int main()':
timeismoney.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i =0; i < ans.size(); i++){
      |                   ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...