Submission #727130

#TimeUsernameProblemLanguageResultExecution timeMemory
727130iskhakkutbilimRoad Closures (APIO21_roads)C++14
5 / 100
48 ms6128 KiB
#include "roads.h" #include <bits/stdc++.h> using namespace std; #define ff first #define ss second vector<long long> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W) { vector<long long> ans; int sub1 = 1, sub2 = 1; vector<int> deg(N, 0); for(int i = 0;i < N-1; i++){ deg[U[i]]++, deg[V[i]]++; if(U[i] != 0) sub1 = 0; if(U[i] != i or V[i] != i+1) sub2 = 0; } long long sum = 0LL; for(int i = 0;i < N-1; i++) sum+= W[i]; if(sub1){ ans.push_back(sum); sort(W.begin(), W.end()); for(int i = N - 2;i >= 0; i--){ sum -= W[i] * 1LL; ans.push_back(sum); } }else if(sub2){ ans.push_back(sum); sum = 0; for(int i = 0;i < N-1; i++){ if(i%2==0) sum+= W[i]; } ans.push_back(sum); sum = 0; for(int i = 0;i < N-1; i++){ if(i%2==1) sum+= W[i]; } if(ans.back()>sum){ ans.pop_back(); ans.push_back(sum); } while(ans.size() < N) ans.push_back(0LL); }else{ } if(ans.size() != N) assert(false); return ans; } //main(){ // int N; cin >> N; // vector<int> U(N), V(N), W(N); // for(int i = 0;i < N-1; i++){ // cin >> U[i] >> V[i]; // } // for(int i = 0;i < N-1; i++) cin >> W[i]; // // vector<long long> ans = minimum_closure_costs(N, U, V, W); // //}

Compilation message (stderr)

roads.cpp: In function 'std::vector<long long int> minimum_closure_costs(int, std::vector<int>, std::vector<int>, std::vector<int>)':
roads.cpp:39:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |   while(ans.size() < N) ans.push_back(0LL);
      |         ~~~~~~~~~~~^~~
roads.cpp:43:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |  if(ans.size() != N) assert(false);
      |     ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...