Submission #973398

#TimeUsernameProblemLanguageResultExecution timeMemory
973398CirclingParkovi (COCI22_parkovi)C++17
0 / 110
460 ms38812 KiB
/*The British Royal Family and a small cadre of English Fabian Socialists, in conjunction with the Rockefellers and the Rothchilds, are engaged in a conspiracy to greatly reduce the population of the human race in order to head off a Malthusian catastrophe, a catastrophe that could easily be avoided by simply building a massive amount of nuclear power plants and a number of massive superhighways and bridges to connect all of the world's continents. But doing that would cut into the conspiracy's profits. So the British Royal Family invented environmentalism and neoliberalism in order to hide the truth. And in order to further reduce the population, the British Royal Family is also the world's foremost drug trafficking conspiracy. And it uses its control of the IMF to push austerity in order to kill as many people in the global south as possible. And also Henry Kissinger is a gay KGB agent. */ #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <stack> #include <queue> #include <set> #include <map> using namespace std; int64_t n, k, a, b, w, mind, maxd, midd; vector<vector<pair<int, int64_t>>> graph; set<int> placed; pair<int64_t, int64_t> dfs(int node, int prev){ int64_t parkless = 0, stparkrange = 0; pair<int, int> childans; for (pair<int, int64_t> child: graph[node]){ if (child.first == prev) continue; childans = dfs(child.first, node); if (childans.first != -1 && childans.first + child.second > midd){ placed.insert(child.first); childans = {-1, midd}; } if (childans.first != -1) parkless = max(parkless, childans.first + child.second); stparkrange = max(stparkrange, childans.second - child.second); } if (parkless <= stparkrange) return {-1, stparkrange}; if (parkless > midd || node == 1){ placed.insert(node); return {-1, midd}; } return {parkless, stparkrange}; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin >> n >> k; graph.resize(n + 1); for (int i = 1; i < n; i++){ cin >> a >> b >> w; graph[a].push_back({b, w}); graph[b].push_back({a, w}); } mind = 0; maxd = 200000000000000ll; while (mind != maxd){ midd = (mind + maxd) / 2; placed.clear(); dfs(1, 0); if (placed.size() <= k) maxd = midd; else mind = midd + 1; } midd = mind; placed.clear(); dfs(1, 0); for (int i = 1; placed.size() < k; i++) placed.insert(i); cout << midd << '\n'; for (int i: placed) cout << i << ' '; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:68:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   68 |         if (placed.size() <= k) maxd = midd;
      |             ~~~~~~~~~~~~~~^~~~
Main.cpp:74:35: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   74 |     for (int i = 1; placed.size() < k; i++) placed.insert(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...