Submission #156809

#TimeUsernameProblemLanguageResultExecution timeMemory
156809popovicirobertMeetings (JOI19_meetings)C++14
100 / 100
1212 ms1016 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; inline void myBridge(int x, int y) { if(x > y) swap(x, y); //cerr << x << " " << y << "\n"; Bridge(x, y); } void solve(vector <int> &nodes, int par) { int n = nodes.size(); if(n == 1) { myBridge(par, nodes[0]); n--; } if(n == 0) return ; vector < pair <int, int> > arr; vector <int> path; int nod = nodes[rand() % n]; for(auto it : nodes) { if(it == nod) continue; int cur = Query(par, it, nod); if(cur == it) { if(cur != par && cur != nod) path.push_back(cur); } else { arr.push_back({cur, it}); } } sort(path.begin(), path.end()); path.resize(unique(path.begin(), path.end()) - path.begin()); sort(arr.begin(), arr.end()); /*cerr << par << " " << nod << "\n"; for(auto it : arr) { cerr << it.second << " "; } cerr << "\n";*/ if(path.empty()) { myBridge(par, nod); } else { sort(path.begin(), path.end(), [&](const int &x, const int &y) { return Query(par, x, y) == x; }); myBridge(par, path[0]); for(int i = 0; i + 1 < path.size(); i++) { myBridge(path[i], path[i + 1]); } myBridge(path.back(), nod); } int i = 0; while(i < arr.size()) { vector <int> aux; int j = i; while(j < arr.size() && arr[i].first == arr[j].first) { aux.push_back(arr[j].second); j++; } solve(aux, arr[i].first); //cerr << j << " " << arr.size() << "\n"; i = j; } } void Solve(int n) { srand(time(NULL)); vector <int> nodes(n - 1); iota(nodes.begin(), nodes.end(), 1); solve(nodes, 0); }

Compilation message (stderr)

meetings.cpp: In function 'void solve(std::vector<int>&, int)':
meetings.cpp:53:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i + 1 < path.size(); i++) {
                  ~~~~~~^~~~~~~~~~~~~
meetings.cpp:60:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(i < arr.size()) {
        ~~^~~~~~~~~~~~
meetings.cpp:63:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(j < arr.size() && arr[i].first == arr[j].first) {
         ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...