#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> g[90005];
int depth[90005], par[90005];
vector<int> ud[90005];
void dfs(int u, int p, int j, int d){
depth[u] = d;
par[u] = j;
ud[d].push_back(u);
for(int i=0;i<g[u].size();i++){
int v = g[u][i].first, j = g[u][i].second;
if(v == p) continue;
dfs(v, u, j, d+1);
}
}
void find_pair(int n, std::vector<int> u, std::vector<int> v, int a, int b){
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));
}
dfs(0, -1, 0, 0);
vector<int> w;
w.resize(m);
LL base = ask(w);
int lo = 1, hi = n, dd = 0, s = 0, t = 0;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int j=mid;j<=n;j++){
for(int k=0;k<ud[j].size();j++){
int u = ud[j][k];
w[par[u]] = 1;
}
}
LL tmp = ask(w);
if(tmp > base) lo = mid+1, dd = mid;
else hi = mid-1;
}
lo = 0, hi = ud[dd].size()-1;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int j=0;j<=mid;j++){
int u = ud[dd][j];
w[par[u]] = 1;
}
LL tmp = ask(w);
if(tmp > base) hi = mid-1, s = ud[dd][mid];
else lo = mid+1;
}
for(int i=0;i<=n;i++) ud[i].clear();
dfs(s, -1, 0, 0);
lo = 1, hi = n;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int j=mid;j<=n;j++){
for(int k=0;k<ud[j].size();j++){
int u = ud[j][k];
w[par[u]] = 1;
}
}
LL tmp = ask(w);
if(tmp > base) lo = mid+1, dd = mid;
else hi = mid-1;
}
lo = 0, hi = ud[dd].size()-1;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int j=0;j<=mid;j++){
int u = ud[dd][j];
w[par[u]] = 1;
}
LL tmp = ask(w);
if(tmp > base) hi = mid-1, t = ud[dd][mid];
else lo = mid+1;
}
answer(s, t);
}
Compilation message
highway.cpp: In function 'void dfs(int, int, int, int)':
highway.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[u].size();i++){
~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:36:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<ud[j].size();j++){
~^~~~~~~~~~~~~
highway.cpp:64:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<ud[j].size();j++){
~^~~~~~~~~~~~~
# |
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 |
7 ms |
4600 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
5912 KB |
Output is correct |
2 |
Correct |
54 ms |
7292 KB |
Output is correct |
3 |
Correct |
65 ms |
8656 KB |
Output is correct |
4 |
Correct |
202 ms |
16976 KB |
Output is correct |
5 |
Correct |
173 ms |
16888 KB |
Output is correct |
6 |
Correct |
160 ms |
16968 KB |
Output is correct |
7 |
Correct |
181 ms |
16892 KB |
Output is correct |
8 |
Correct |
203 ms |
16880 KB |
Output is correct |
9 |
Correct |
193 ms |
16880 KB |
Output is correct |
# |
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 |
Runtime error |
57 ms |
24588 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
51 ms |
24600 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |