Submission #582040

#TimeUsernameProblemLanguageResultExecution timeMemory
5820408e7Highway Tolls (IOI18_highway)C++17
0 / 100
331 ms15832 KiB
#include "highway.h" //Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 100005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); vector<pii> adj[maxn], g[maxn]; ll mind; vector<int> tmp; int ord[maxn]; void dfs(int n, int par, int &cur, int lim) { ord[cur++] = n; if (cur > lim) return; for (auto [v, id]:adj[n]) { //debug(n, v); if (v != par && cur + 1 <= lim) { tmp[id] = 0; //debug("edge", n, v); dfs(v, n, cur, lim); if (cur > lim) return; } } } int m, edges; void getnode(int n, int par, int &cur, int d, vector<int> &vec) { cur++; if (d == edges) { vec.push_back(cur); } for (auto [v, id]:adj[n]) { if (v != par) { getnode(v, n, cur, d+1, vec); } } } int type = 0; int getind(int n, int root) { int low = 0, up = n; vector<int> poss; if (type == 1) { int ini = 0; getnode(root, -1, ini, 0, poss); up = poss.size(); } pary(poss.begin(), poss.end()); tmp.resize(m, 0); dfs(root, -1,low, 1<<30); low = 0; while (low < up - 1) { int mid = (low + up) / 2; for (int i = 0;i < m;i++) tmp[i] = 1; int ini = 0; if (type) dfs(root, -1, ini, poss[mid]); else dfs(root, -1, ini, mid); //debug(low, mid, up); //pary(tmp.begin(), tmp.end()); ll val = ask(tmp); if (val == mind) { up = mid; } else { low = mid; } } //debug(up, ord[up-1]); return (type ? ord[poss[up]-1] : ord[low]); } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { int M = U.size(); m = M; vector<int> ini(M, 0); mind = ask(ini); edges = mind / A; int low = 0, up = M; while (low < up - 1) { int mid = (low + up) / 2; for (int i = 0;i < M;i++) { if (i < mid) ini[i] = 0; else ini[i] = 1; } if (ask(ini) == mind) { up = mid; } else { low = mid; } } for (int i = 0;i < M;i++) { g[U[i]].push_back({V[i], i}); g[V[i]].push_back({U[i], i}); } //debug(low, U[low], V[low]); vector<bool> vis(N, 0); int root = U[low]; queue<int> que; que.push(root); vis[root] = 1; while (que.size()) { int cur = que.front();que.pop(); vis[cur] = 1; for (auto [v, id]:g[cur]) { if (!vis[v]) { vis[v] = 1; adj[cur].push_back({v, id}); adj[v].push_back({cur, id}); que.push(v); } } } int s = getind(N, root); type = 1; int t = getind(N, s); debug(s, t); answer(s, t); } /* 4 3 5 8 1 3 0 1 0 2 1 3 */

Compilation message (stderr)

highway.cpp: In function 'int getind(int, int)':
highway.cpp:14:19: warning: statement has no effect [-Wunused-value]
   14 | #define pary(...) 0
      |                   ^
highway.cpp:63:2: note: in expansion of macro 'pary'
   63 |  pary(poss.begin(), poss.end());
      |  ^~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
highway.cpp:135:2: note: in expansion of macro 'debug'
  135 |  debug(s, t);
      |  ^~~~~
#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...