제출 #999580

#제출 시각아이디문제언어결과실행 시간메모리
999580amine_aroua통행료 (IOI18_highway)C++17
90 / 100
226 ms39200 KiB
#include<bits/stdc++.h> using namespace std; #define intt long long #define pb push_back #define forr(i , x , y) for(int i = x; i <= y;i++) #define fore(i , n) for(int i = 0 ; i < n;i++) #define forn(i ,x , y) for(int i = x ; i >= y;i--) long long ask(const vector<int> &w); void answer(int s, int t); const int MAXN = 90001; intt a , b; int n; vector<pair<int ,int>> adj[MAXN]; vector<int> zeros , ones; intt val; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); map<vector<int> , intt> mp; intt myask(vector<int> v) { if(mp.count(v)) return mp[v]; return mp[v] = ask(v); } int go(int root) { vector<int> dist(n , n); vector<bool> vis(n , 0); dist[root] = 0; queue<int> q; q.push(root); while(!q.empty()) { int x = q.front(); q.pop(); if(vis[x]) continue; vis[x] = 1; for(auto [u , i] : adj[x]) { if(dist[u] > dist[x] + 1) { dist[u] = dist[x] + 1; q.push(u); } } } vector<pair<int ,int>> nds; fore(i , n) nds.pb({dist[i] , i}); sort(nds.rbegin() , nds.rend()); int l = 0 , r = (int)nds.size(); vector<int> asked = ones; while(l + 1 < r) { int mid = (l + r)/2; asked = zeros; forr(j , 0 , mid - 1) { for(auto i : adj[nds[j].second])asked[i.second] = 1; } if(myask(asked) == val) l = mid; else r = mid; } return nds[l].second; } void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { n = N; a = A , b = B; int m = (int)U.size(); zeros.assign(m , 0); ones.assign(m , 1); fore(i , N)adj[i].clear(); val = myask(zeros); fore(i , m) { adj[U[i]].pb({V[i] , i}); adj[V[i]].pb({U[i] , i}); } int S = go(go(0)); answer(S , go(S)); }
#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...