Submission #723345

#TimeUsernameProblemLanguageResultExecution timeMemory
723345groshitimeismoney (balkan11_timeismoney)C++17
100 / 100
1040 ms1108 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int t[20000][4]; int MAX=1000; int ojc[3000]; int find_u(int x) { if(ojc[x]==x) return x; return ojc[x]=find_u(ojc[x]); } void union_f(int x,int y) { x=find_u(x); y=find_u(y); ojc[x]=y; } int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,m,x,y,s,c; cin>>n>>m; for(int i=1;i<=m;i++) { cin>>x>>y>>s>>c; t[i][0]=x; t[i][1]=y; t[i][2]=s; t[i][3]=c; } vector<pair<int,int> > Q; vector<pair<int,int> > wypisz; int S=1e9; int T=1e9; for(int i=0;i<=MAX;i++) { for(int j=0;j<n;j++) ojc[j]=j; vector<pair<int,int> > mam; Q.clear(); for(int j=1;j<=m;j++) Q.push_back({i*t[j][2]+(MAX-i)*t[j][3],j}); sort(Q.begin(),Q.end()); int wynik=0; s=0,c=0; for(int i=0;i<Q.size();i++) { int kto=Q[i].second; if(find_u(t[kto][0])==find_u(t[kto][1])) continue; s+=t[kto][3]; c+=t[kto][2]; union_f(t[kto][0],t[kto][1]); mam.push_back({t[kto][0],t[kto][1]}); } if(s*c<S*T) { S=s; T=c; wypisz=mam; } } cout<<T<<" "<<S<<"\n"; for(int i=0;i<wypisz.size();i++) cout<<wypisz[i].first<<" "<<wypisz[i].second<<"\n"; return 0; }

Compilation message (stderr)

timeismoney.cpp: In function 'int32_t main()':
timeismoney.cpp:49:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i=0;i<Q.size();i++)
      |                     ~^~~~~~~~~
timeismoney.cpp:47:13: warning: unused variable 'wynik' [-Wunused-variable]
   47 |         int wynik=0;
      |             ^~~~~
timeismoney.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<wypisz.size();i++)
      |                 ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...