Submission #832910

#TimeUsernameProblemLanguageResultExecution timeMemory
832910tolbiFireworks (APIO16_fireworks)C++17
7 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define int long long using namespace std; #define deci(x) int x;cin>>x; #define INF LONG_LONG_MAX const int MOD = 1e9+7; int32_t main(){ deci(n);deci(m); vector<vector<pair<int,int>>> tree(n+m); vector<vector<int>> arr(n+m); for (int i = 1; i < n+m; ++i) { int u = i+1; deci(v);deci(w); tree[u-1].push_back({v-1,w}); tree[v-1].push_back({u-1,w}); arr[u-1].push_back(v-1); arr[v-1].push_back(u-1); } auto solve = [&](int x){ int ans = 0; auto dfs = [&](int node, int lnode, int crr, auto dfs)->int{ if (node>=n){ return crr; } vector<int> hueh; for (int i = 0; i < tree[node].size(); i++){ if (tree[node][i].first==lnode) continue; hueh.push_back(dfs(tree[node][i].first,node,tree[node][i].second+crr,dfs)); } sort(hueh.begin(), hueh.end()); int l = hueh[hueh.size()/2]; int r = l; if (hueh.size()%2==0) r=hueh[hueh.size()/2+1]; for (int i = 0; i < hueh.size(); i++){ ans+=abs(hueh[i]-hueh[hueh.size()/2]); } if (r<x) return r; if (l>x) return l; return x; }; dfs(0,-1,0,dfs); return ans; }; int l = 0, r = INF; while (l<r){ int mid = l+(r-l)/2; if (solve(mid)<=solve(mid+1)){ r=mid; } else l = mid+1; } cout<<solve(l)<<endl; }

Compilation message (stderr)

fireworks.cpp: In lambda function:
fireworks.cpp:35:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for (int i = 0; i < hueh.size(); i++){
      |                    ~~^~~~~~~~~~~~~
fireworks.cpp: In instantiation of 'main()::<lambda(long long int)>::<lambda(long long int, long long int, long long int, auto:23)> [with auto:23 = main()::<lambda(long long int)>::<lambda(long long int, long long int, long long int, auto:23)>]':
fireworks.cpp:42:18:   required from here
fireworks.cpp:27: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]
   27 |    for (int i = 0; i < tree[node].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
fireworks.cpp:35:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    for (int i = 0; i < hueh.size(); i++){
      |                    ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...