Submission #102845

#TimeUsernameProblemLanguageResultExecution timeMemory
102845wxh010910Highway Tolls (IOI18_highway)C++17
100 / 100
347 ms11068 KiB
#include <bits/stdc++.h> #include "highway.h" using namespace std; void find_pair(int n, vector<int> u, vector<int> v, int a, int b) { vector<vector<pair<int, int>>> adj(n); int m = u.size(); vector<int> w(m); for (int i = 0; i < m; ++i) { adj[u[i]].emplace_back(v[i], i); adj[v[i]].emplace_back(u[i], i); } long long value = ask(w); int l = 0, r = m - 2, e = m - 1; while (l <= r) { int mid = l + r >> 1; for (int i = 0; i < m; ++i) { w[i] = i <= mid; } if (ask(w) != value) { e = mid; r = mid - 1; } else { l = mid + 1; } } vector<int> tree, left, right, visit(n); queue<int> q; q.push(u[e]); visit[u[e]] = 1; left.push_back(u[e]); q.push(v[e]); visit[v[e]] = 2; right.push_back(v[e]); tree.push_back(e); while (!q.empty()) { int x = q.front(); q.pop(); for (auto p : adj[x]) { int y = p.first, w = p.second; if (!visit[y]) { tree.push_back(w); q.push(y); if (visit[x] == 1) { visit[y] = 1; left.push_back(y); } else { visit[y] = 2; right.push_back(y); } } } } auto solve = [&](vector<int> nodes) { int l = 0, r = nodes.size() - 2, p = nodes.size() - 1; while (l <= r) { int mid = l + r >> 1; vector<bool> ban(n, false); for (int i = mid + 1; i < nodes.size(); ++i) { ban[nodes[i]] = true; } for (int i = 0; i < m; ++i) { w[i] = 1; } for (auto e : tree) { if (!ban[u[e]] && !ban[v[e]]) { w[e] = 0; } } if (ask(w) == value) { p = mid; r = mid - 1; } else { l = mid + 1; } } return nodes[p]; }; answer(solve(left), solve(right)); }

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:17:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
highway.cpp: In lambda function:
highway.cpp:59:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
       int mid = l + r >> 1;
                 ~~^~~
highway.cpp:61:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = mid + 1; i < nodes.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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...