#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> g[90005], g2[90005];
bool vis[90005];
int arr[2][90005];
int par[90005];
int k = 1;
void dfs(int u, int p, int j, int d, int t){
par[u] = j;
arr[t][k++] = u;
for(int i=0;i<g2[u].size();i++){
int v = g2[u][i].first, j = g2[u][i].second;
if(v == p) continue;
dfs(v, u, j, d+1, t);
}
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int a, int b){
int s, t;
int m = U.size();
for(int i=0;i<m;i++){
int a = U[i], b = V[i];
g[a].push_back(pii(b, i));
g[b].push_back(pii(a, i));
}
vector<int> w;
w.resize(m);
LL base = ask(w);
int lo = 0, hi = m-1, j = 0;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int i=0;i<=mid;i++) w[i] = 1;
LL tmp = ask(w);
if(tmp > base) j = mid, hi = mid-1;
else lo = mid+1;
}
int u = U[j], v = V[j];
vis[u] = 1;
vis[v] = 1;
queue<int> q;
q.push(u);
q.push(v);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i=0;i<g[u].size();i++){
int v = g[u][i].first, j = g[u][i].second;
if(vis[v]) continue;
vis[v] = 1;
g2[u].push_back(pii(v, j));
g2[v].push_back(pii(u, j));
}
}
k = 1;
dfs(u, -1, 0, 0, 0);
int sz1 = k-1;
k = 1;
dfs(v, -1, 0, 0, 1);
int sz2 = k-1;
lo = 1, hi = sz1;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int i=mid;i<=sz1;i++){
int u = arr[0][i];
w[par[u]] = 1;
}
LL tmp = ask(w);
if(tmp > base) s = arr[0][mid], lo = mid+1;
else hi = mid-1;
}
lo = 1, hi = sz2;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int i=mid;i<=sz2;i++){
int u = arr[1][i];
w[par[u]] = 1;
}
LL tmp = ask(w);
if(tmp > base) t = arr[1][mid], lo = mid+1;
else hi = mid-1;
}
answer(s, t);
}
Compilation message
highway.cpp: In function 'void dfs(int, int, int, int, int)':
highway.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g2[u].size();i++){
~^~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:49:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[u].size();i++){
~^~~~~~~~~~~~
highway.cpp:89:11: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
answer(s, t);
~~~~~~^~~~~~
highway.cpp:89:11: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4560 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4600 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
5032 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4604 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
5184 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
5140 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |