Submission #120381

#TimeUsernameProblemLanguageResultExecution timeMemory
120381onjo0127Highway Tolls (IOI18_highway)C++11
90 / 100
1036 ms11024 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; int n, M; long long ori; vector<pii> adj[90009]; int D[90009]; int any(vector<int> S) { int K = S.size(); int l = 0, r = K-1; while(l <= r) { if(l == r) return S[l]; int m = l+r >> 1; vector<int> W(M, 0); for(int i=0; i<=m; i++) for(auto& it: adj[S[i]]) W[it.second] = 1; if(ask(W) != ori) r = m; else l = m+1; } return S[r+1]; } vector<int> f(int root) { int c = 1; for(int i=0; i<n; i++) D[i] = 0; queue<int> que; que.push(root); D[root] = 1; while(que.size()) { int sz = que.size(); while(sz--) { int now; now = que.front(); que.pop(); for(auto& it: adj[now]) { if(!D[it.first]) { D[it.first] = c+1; que.push(it.first); } } } ++c; } vector<int> S; for(int i=0; i<n; i++) S.push_back(i); sort(S.begin(), S.end(), [&](int P, int Q) {return D[P] > D[Q];}); return S; } void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { n = N; M = U.size(); for(int i=0; i<M; i++) { adj[U[i]].push_back({V[i], i}); adj[V[i]].push_back({U[i], i}); } vector<int> W(M, 0); ori = ask(W); int P = any(f(any(f(0)))); int Q = any(f(P)); //printf("S: %d, T: %d\n", P, Q); answer(P, Q); }

Compilation message (stderr)

highway.cpp: In function 'int any(std::vector<int>)':
highway.cpp:16:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
#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...