This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<pair<int, int>> adj[100100], G[100100];
vector<int> w, rans;
int n, m, a, b, P[100100], E[100100], par[100100], cnt = -1;
ll c0;
ll myask(vector<int> &w){
return ask(w);
}
int search1(){
int l = 0, r = n-1, ans = -1;
while(l<=r){
int m = (l+r)>>1;
if (l==0 && r>=60000) m = 30000;
fill(w.begin(), w.end(), 0);
for (int i=0;i<=m;i++) for (auto &[v, j]:adj[i]) w[j] = 1;
if (myask(w)==c0) ans = m, l = m+1;
else r = m-1;
}
fill(w.begin(), w.end(), 0);
for (int i=0;i<=ans;i++) for (auto &[v, j]:adj[i]) w[j] = 1;
return ans + 1;
}
bool visited[100100];
void bfs(int s){
queue<int> q;
q.push(s);
visited[s] = 1;
while(!q.empty()){
int cur = q.front(); q.pop();
for (auto &[nxt, i]:adj[cur]) if (!w[i] && !visited[nxt]){
G[cur].emplace_back(nxt, i);
G[nxt].emplace_back(cur, i);
visited[nxt] = 1;
w[i] = -1;
q.push(nxt);
}
}
}
void dfs(int s, int pa = -1, int idx = -1, int val = 0){
P[++cnt] = s;
E[cnt] = idx;
par[cnt] = val;
int tmp = cnt;
for (auto &[v, i]:G[s]) if (v!=pa){
dfs(v, s, i, tmp);
}
}
int search2(int mx){
int l = 1, r = mx, ans = mx+1;
while(l<=r){
int m = (l+r)>>1;
for (int i=1;i<=cnt;i++) w[E[i]] = 0;
for (int i=m;i<=mx;i++) w[E[i]] = 1;
if (myask(w)==c0) ans = m, r = m-1;
else l = m+1;
}
rans.push_back(P[--ans]);
if (ans==0) return 0;
for(;par[ans];ans=par[ans]);
//printf("ret: %d\n", ans);
return ans;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
n = N, a = A, b = B, m = U.size();
for (int i=0;i<m;i++){
adj[U[i]].emplace_back(V[i], i);
adj[V[i]].emplace_back(U[i], i);
}
w.resize(m);
c0 = myask(w);
int x = search1();
bfs(x);
for (int i=0;i<m;i++){
if (w[i]==-1) w[i] = 0;
else w[i] = 1;
}
dfs(x);
/*printf("x: %d\n", x);
printf("E: ");
for (int i=0;i<=cnt;i++) printf("%d ", E[i]);
printf("\nP: ");
for (int i=0;i<=cnt;i++) printf("%d ", P[i]);
printf("\npar: ");
for (int i=0;i<=cnt;i++) printf("%d ", par[i]);
printf("\n");*/
search2(search2(cnt)-1);
answer(rans[0], rans[1]);
}
Compilation message (stderr)
highway.cpp: In function 'int search1()':
highway.cpp:21:43: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
21 | for (int i=0;i<=m;i++) for (auto &[v, j]:adj[i]) w[j] = 1;
| ^
highway.cpp:28:41: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
28 | for (int i=0;i<=ans;i++) for (auto &[v, j]:adj[i]) w[j] = 1;
| ^
highway.cpp: In function 'void bfs(int)':
highway.cpp:39:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | for (auto &[nxt, i]:adj[cur]) if (!w[i] && !visited[nxt]){
| ^
highway.cpp: In function 'void dfs(int, int, int, int)':
highway.cpp:55:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
55 | for (auto &[v, i]:G[s]) if (v!=pa){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |