Submission #744785

#TimeUsernameProblemLanguageResultExecution timeMemory
744785nguyentunglamHighway Tolls (IOI18_highway)C++17
23 / 100
251 ms19812 KiB
#include "highway.h" #include<bits/stdc++.h> using namespace std; const int N = 2e5 + 10; vector<pair<int, int>> adj[N]; vector<int> ke[N]; bool mark[N]; int n, m, par[N], st[N], cnt, init; void dfs(int u) { st[u] = ++cnt; for(int &v : ke[u]) dfs(v); } int Find(int s) { cnt = 0; for(int i = 0; i < n; i++) st[i] = 0; dfs(s); int l = 1, r = cnt, ret = 1; while (l <= r) { int mid = l + r >> 1; vector<int> w(m); for(int i = 0; i < m; i++) w[i] = mark[i]; for(int i = 0; i < n; i++) if (st[i] > mid) w[par[i]] = 1; if (ask(w) == init) { ret = mid; r = mid - 1; } else l = mid + 1; } for(int i = 0; i < n; i++) if (st[i] == ret) return i; } void find_pair(int _n, std::vector<int> u, std::vector<int> v, int a, int b) { m = u.size(); n = _n; for(int i = 0; i < m; i++) { adj[u[i]].emplace_back(v[i], i); adj[v[i]].emplace_back(u[i], i); } vector<int> w(m); init = ask(w); int l = 0, r = m - 1, idx = -1; while (l <= r) { int mid = l + r >> 1; for(int i = 0; i < m; i++) w[i] = 0; for(int i = 0; i <= mid; i++) w[i] = 1; if (ask(w) > init) idx = mid, r = mid - 1; else l = mid + 1; } for(int i = 0; i < m; i++) mark[i] = 1; for(int i = 0; i < n; i++) par[i] = -1; mark[idx] = 0; par[u[idx]] = par[v[idx]] = idx; queue<int> q; q.push(u[idx]); q.push(v[idx]); while (!q.empty()) { int u = q.front(); q.pop(); for(auto &[v, i] : adj[u]) if (par[v] < 0) { par[v] = i; mark[i] = 0; ke[u].push_back(v); q.push(v); } } answer(Find(u[idx]), Find(v[idx])); }

Compilation message (stderr)

highway.cpp: In function 'int Find(int)':
highway.cpp:21:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         int mid = l + r >> 1;
      |                   ~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:46:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         int mid = l + r >> 1;
      |                   ~~^~~
highway.cpp: In function 'int Find(int)':
highway.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^
#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...