#include "highway.h"
#include<bits/stdc++.h>
#define K 1<<17
using namespace std;
int par[K],dep[K],ord[K],pos[K],CC,bfspar[2][K],bfspari[2][K],bfsdis[2][K];
vector<pair<int,int>>adj[K];
void bfs(int n,int i){
queue<int>q;
memset(bfsdis[i],-1,sizeof par);
q.push(n);
bfsdis[i][n]=0;
bfspar[i][n]=-1;
while(q.size()){
int x=q.front(),d=bfsdis[i][x]; q.pop();
for(auto [j,k]:adj[x]) if(bfsdis[i][j]<0)
bfspar[i][j]=x,bfspari[i][j]=k,
bfsdis[i][j]=d+1,q.push(j);
}
}
void dfs(int n,int in){
pos[n]=++CC;
for(auto [i,k]:adj[n])
if(bfspar[in][i]==n)
dep[i]=dep[n]+1,
par[i]=k,dfs(i,in);
}
int whicho(int pivot,int N,int ind,int M,vector<int>v,long long D){
dfs(pivot,ind);
sort(v.begin(),v.end(),[](int a,int b){
return pos[a]<pos[b];
});
int l=1,r=v.size()-1,res=1;
while(l<=r){
int mid=l+r>>1;
vector<int>V(M,1);
for(int i=mid;i<v.size();i++)
V[bfspari[ind][v[i]]]=0;
if(ask(V)<D)
l=res=mid+1;
else r=mid-1;
}
return v[res-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++)
adj[U[i]].push_back({V[i],i}),
adj[V[i]].push_back({U[i],i});
long long D=ask(vector<int>(M,0))/A;
int res=1e9,l=1,r=M-1;
while(l<=r){
int mid=l+r>>1;
vector<int>v(M);
for(int i=0;i<mid;i++)
v[i]=1;
if(ask(v)>D*A)
res=r=mid-1;
else l=mid+1;
}
int a=U[res],b=V[res];
bfs(a,0);
bfs(b,1);
vector<int>sta,stb;
for(int i=0;i<N;i++)
if(bfsdis[0][i]<bfsdis[1][i])
sta.push_back(i);
else if(bfsdis[0][i]-bfsdis[1][i])
stb.push_back(i);
answer(whicho(a,N,0,M,sta,D*B),whicho(b,N,1,M,stb,D*B));
}
Compilation message
highway.cpp: In function 'int whicho(int, int, int, int, std::vector<int>, long long int)':
highway.cpp:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid=l+r>>1;
| ~^~
highway.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=mid;i<v.size();i++)
| ~^~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:52:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
2 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4440 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4440 KB |
Output is correct |
9 |
Correct |
3 ms |
4440 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4440 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
11 ms |
5388 KB |
Output is correct |
3 |
Correct |
94 ms |
12912 KB |
Output is correct |
4 |
Correct |
108 ms |
12908 KB |
Output is correct |
5 |
Correct |
106 ms |
12916 KB |
Output is correct |
6 |
Correct |
94 ms |
12892 KB |
Output is correct |
7 |
Correct |
93 ms |
12896 KB |
Output is correct |
8 |
Correct |
94 ms |
13052 KB |
Output is correct |
9 |
Correct |
85 ms |
12912 KB |
Output is correct |
10 |
Correct |
84 ms |
12912 KB |
Output is correct |
11 |
Correct |
111 ms |
14012 KB |
Output is correct |
12 |
Correct |
113 ms |
14832 KB |
Output is correct |
13 |
Correct |
96 ms |
14064 KB |
Output is correct |
14 |
Correct |
97 ms |
14160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6080 KB |
Output is correct |
2 |
Correct |
20 ms |
7512 KB |
Output is correct |
3 |
Correct |
26 ms |
10628 KB |
Output is correct |
4 |
Correct |
61 ms |
16720 KB |
Output is correct |
5 |
Correct |
66 ms |
16780 KB |
Output is correct |
6 |
Correct |
72 ms |
18292 KB |
Output is correct |
7 |
Correct |
66 ms |
19036 KB |
Output is correct |
8 |
Correct |
70 ms |
17788 KB |
Output is correct |
9 |
Correct |
64 ms |
17624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4692 KB |
Output is correct |
2 |
Correct |
14 ms |
5464 KB |
Output is correct |
3 |
Correct |
69 ms |
11060 KB |
Output is correct |
4 |
Correct |
87 ms |
12916 KB |
Output is correct |
5 |
Correct |
83 ms |
12904 KB |
Output is correct |
6 |
Correct |
75 ms |
12908 KB |
Output is correct |
7 |
Correct |
87 ms |
12912 KB |
Output is correct |
8 |
Correct |
76 ms |
12900 KB |
Output is correct |
9 |
Correct |
102 ms |
12904 KB |
Output is correct |
10 |
Correct |
103 ms |
12916 KB |
Output is correct |
11 |
Correct |
93 ms |
13796 KB |
Output is correct |
12 |
Correct |
104 ms |
15052 KB |
Output is correct |
13 |
Correct |
96 ms |
14420 KB |
Output is correct |
14 |
Correct |
97 ms |
14256 KB |
Output is correct |
15 |
Correct |
87 ms |
12764 KB |
Output is correct |
16 |
Correct |
97 ms |
12908 KB |
Output is correct |
17 |
Correct |
102 ms |
13912 KB |
Output is correct |
18 |
Correct |
100 ms |
14380 KB |
Output is correct |
19 |
Correct |
96 ms |
12916 KB |
Output is correct |
20 |
Correct |
88 ms |
15176 KB |
Output is correct |
21 |
Correct |
74 ms |
13636 KB |
Output is correct |
22 |
Correct |
70 ms |
13644 KB |
Output is correct |
23 |
Correct |
90 ms |
13428 KB |
Output is correct |
24 |
Correct |
95 ms |
13616 KB |
Output is correct |
25 |
Correct |
107 ms |
18660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
5464 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
5648 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |