#include "highway.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct edge{
int id, v;
};
int N, M, A, B;
vector<vector<edge> > graph;
void dfs(int u, int par, int id, int d, int dist, vector<int>& idlist, vector<int>& vlist){
if(d == dist){
idlist.push_back(id);
vlist.push_back(u);
}
for(edge e : graph[u]) if(e.v!=par){
dfs(e.v, u, e.id, d+1, dist, idlist, vlist);
}
}
int findT(int S, int par, int dist, int id, int dist2){
vector<int> idlist, vlist;
dfs(S, par, id, 0, dist, idlist, vlist);
int L = 0, R = idlist.size();
//for(int i : vlist) //cout<<i<<" ";
//cout<<endl;
//for(int i : idlist) //cout<<i<<" ";
//cout<<endl;
while(L!=R-1){
//cout<<"L: "<< L<< " R: "<<R<<endl;
int Mi = (L+R)/2;
vector<signed> w(M, 0);
for(int i = L; i<Mi; i++){
w[idlist[i]]=1;
}
//cout<<ask(w)<<endl;
if(ask(w)==dist2*A){
L = Mi;
}
else{
R = Mi;
}
}
return vlist[L];
}
int findedge(int dist){
int L = 0, R = M;
while(L!=R-1){
int Mi = (L+R)/2;
vector<signed> w(M, 0);
for(int i = L; i<Mi; i++){
w[i]=1;
}
if(ask(w)==dist*A){
L = Mi;
}
else{
R = Mi;
}
}
return L;
}
void dfs2(int u, int par, int id, vector<signed> & w){
w[id] = 1;
for(edge e : graph[u]) if(e.v!=par){
dfs2(e.v, u, e.id, w);
}
}
void find_pair(signed _N, vector<signed> U, vector<signed> V, signed _A, signed _B) {
N = _N;
M = U.size();
A = _A;
B = _B;
graph.resize(N);
for(int i = 0; i<M; i++){
graph[U[i]].push_back({i, V[i]});
graph[V[i]].push_back({i, U[i]});
}
vector<signed> w(M, 0);
int dist = ask(w)/A;
int ed = findedge(dist);
//cout<<"edge: "<<U[ed]<<" "<<V[ed]<<endl;
dfs2(V[ed], U[ed], ed, w);
int d1 = (ask(w)-dist*A)/(B-A)-1;
int d2 = dist - d1 - 1;
//cout<<"d1: "<<d1<<" d2: "<<d2<<endl;
int S = findT(V[ed], U[ed], d1, ed, dist);
int T = findT(U[ed], V[ed], d2, ed, dist);
answer(S,T);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
328 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
248 KB |
Output is correct |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
408 KB |
Output is correct |
8 |
Correct |
2 ms |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
2 ms |
320 KB |
Output is correct |
11 |
Correct |
2 ms |
244 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
424 KB |
Output is correct |
2 |
Correct |
20 ms |
1328 KB |
Output is correct |
3 |
Correct |
213 ms |
9440 KB |
Output is correct |
4 |
Correct |
171 ms |
9532 KB |
Output is correct |
5 |
Correct |
231 ms |
9536 KB |
Output is correct |
6 |
Correct |
189 ms |
9188 KB |
Output is correct |
7 |
Correct |
179 ms |
9540 KB |
Output is correct |
8 |
Correct |
167 ms |
9248 KB |
Output is correct |
9 |
Correct |
188 ms |
9192 KB |
Output is correct |
10 |
Correct |
189 ms |
9536 KB |
Output is correct |
11 |
Correct |
201 ms |
11028 KB |
Output is correct |
12 |
Correct |
233 ms |
12420 KB |
Output is correct |
13 |
Correct |
210 ms |
11660 KB |
Output is correct |
14 |
Correct |
210 ms |
11800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2180 KB |
Output is correct |
2 |
Correct |
46 ms |
3868 KB |
Output is correct |
3 |
Correct |
67 ms |
5920 KB |
Output is correct |
4 |
Correct |
159 ms |
14920 KB |
Output is correct |
5 |
Correct |
174 ms |
14916 KB |
Output is correct |
6 |
Correct |
159 ms |
16648 KB |
Output is correct |
7 |
Correct |
163 ms |
18164 KB |
Output is correct |
8 |
Correct |
156 ms |
15696 KB |
Output is correct |
9 |
Correct |
157 ms |
16072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
38 ms |
1324 KB |
Output is correct |
3 |
Correct |
122 ms |
7228 KB |
Output is correct |
4 |
Correct |
231 ms |
9444 KB |
Output is correct |
5 |
Correct |
199 ms |
9232 KB |
Output is correct |
6 |
Correct |
146 ms |
9220 KB |
Output is correct |
7 |
Correct |
162 ms |
9104 KB |
Output is correct |
8 |
Correct |
180 ms |
9184 KB |
Output is correct |
9 |
Correct |
201 ms |
9532 KB |
Output is correct |
10 |
Correct |
189 ms |
9540 KB |
Output is correct |
11 |
Correct |
191 ms |
11264 KB |
Output is correct |
12 |
Correct |
219 ms |
12428 KB |
Output is correct |
13 |
Correct |
206 ms |
11920 KB |
Output is correct |
14 |
Correct |
197 ms |
11788 KB |
Output is correct |
15 |
Correct |
219 ms |
9192 KB |
Output is correct |
16 |
Correct |
186 ms |
9192 KB |
Output is correct |
17 |
Correct |
183 ms |
11440 KB |
Output is correct |
18 |
Correct |
197 ms |
12040 KB |
Output is correct |
19 |
Correct |
194 ms |
9188 KB |
Output is correct |
20 |
Correct |
224 ms |
12868 KB |
Output is correct |
21 |
Correct |
158 ms |
11232 KB |
Output is correct |
22 |
Correct |
137 ms |
11232 KB |
Output is correct |
23 |
Correct |
195 ms |
10104 KB |
Output is correct |
24 |
Correct |
157 ms |
10660 KB |
Output is correct |
25 |
Correct |
164 ms |
17832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
408 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
379 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |