#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
vector <pair <int,int> > g[100010];
int pa[100010],dep[100010];
vector <int> is;
void dfs(int cur,int prv,bool r){
if (r) dep[cur]=0;
else dep[cur]=dep[prv]+1;
for (auto i:g[cur]){
if (i.first!=prv){
pa[i.first]=i.second;
is.push_back(i.second);
dfs(i.first,cur,0);
}
}
}
void find_pair(int n,vector <int> u,vector <int> v,int a,int b){
int m=u.size();
vector <int> tt(m,0);
long long dist0=ask(tt);
int l=0,r=m-1;
while (l<r){
int mid=(l+r)/2;
vector <int> tp(m,0);
for (int i=l; i<=mid; i++) tp[i]=1;
long long dist1=ask(tp);
if (dist0!=dist1) r=mid;
else l=mid+1;
}
for (int i=0; i<m; i++){
g[u[i]].push_back({v[i],i});
g[v[i]].push_back({u[i],i});
}
is.clear();
for (int i=0; i<n; i++) dep[i]=-1;
dfs(u[l],v[l],1);
vector <int> tp(m,0);
for (int i:is) tp[i]=1;
long long dist1=ask(tp);
long long d=(dist1-dist0)/(1LL*(b-a));
vector <int> cand;
for (int i=0; i<n; i++){
if (dep[i]==d) cand.push_back(i);
}
while (cand.size()>1){
for (int i=0; i<m; i++) tp[i]=0;
for (int i=0; i<(cand.size()+1)/2; i++) tp[pa[cand[i]]]=1;
dist1=ask(tp);
vector <int> nw;
if (dist0!=dist1){
for (int i=0; i<(cand.size()+1)/2; i++) nw.push_back(cand[i]);
} else {
for (int i=(cand.size()+1)/2; i<cand.size(); i++) nw.push_back(cand[i]);
}
cand=nw;
}
int ans=cand[0];
is.clear();
for (int i=0; i<n; i++) dep[i]=-1;
dfs(v[l],u[l],1);
for (int i=0; i<m; i++) tp[i]=0;
for (int i:is) tp[i]=1;
dist1=ask(tp);
d=(dist1-dist0)/(1LL*(b-a));
cand.clear();
for (int i=0; i<n; i++){
if (dep[i]==d) cand.push_back(i);
}
while (cand.size()>1){
for (int i=0; i<m; i++) tp[i]=0;
for (int i=0; i<(cand.size()+1)/2; i++) tp[pa[cand[i]]]=1;
dist1=ask(tp);
vector <int> nw;
if (dist0!=dist1){
for (int i=0; i<(cand.size()+1)/2; i++) nw.push_back(cand[i]);
} else {
for (int i=(cand.size()+1)/2; i<cand.size(); i++) nw.push_back(cand[i]);
}
cand=nw;
}
answer(ans,cand[0]);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i=0; i<(cand.size()+1)/2; i++) tp[pa[cand[i]]]=1;
| ~^~~~~~~~~~~~~~~~~~
highway.cpp:52:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i=0; i<(cand.size()+1)/2; i++) nw.push_back(cand[i]);
| ~^~~~~~~~~~~~~~~~~~
highway.cpp:54:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i=(cand.size()+1)/2; i<cand.size(); i++) nw.push_back(cand[i]);
| ~^~~~~~~~~~~~
highway.cpp:72:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i=0; i<(cand.size()+1)/2; i++) tp[pa[cand[i]]]=1;
| ~^~~~~~~~~~~~~~~~~~
highway.cpp:76:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for (int i=0; i<(cand.size()+1)/2; i++) nw.push_back(cand[i]);
| ~^~~~~~~~~~~~~~~~~~
highway.cpp:78:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i=(cand.size()+1)/2; i<cand.size(); i++) nw.push_back(cand[i]);
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3408 KB |
Output is correct |
2 |
Correct |
1 ms |
3400 KB |
Output is correct |
3 |
Correct |
1 ms |
3396 KB |
Output is correct |
4 |
Correct |
1 ms |
3400 KB |
Output is correct |
5 |
Correct |
1 ms |
3400 KB |
Output is correct |
6 |
Correct |
1 ms |
3396 KB |
Output is correct |
7 |
Correct |
1 ms |
3400 KB |
Output is correct |
8 |
Correct |
1 ms |
3404 KB |
Output is correct |
9 |
Correct |
1 ms |
3404 KB |
Output is correct |
10 |
Correct |
1 ms |
3400 KB |
Output is correct |
11 |
Correct |
2 ms |
3848 KB |
Output is correct |
12 |
Correct |
1 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
8 ms |
4112 KB |
Output is correct |
3 |
Correct |
73 ms |
9556 KB |
Output is correct |
4 |
Correct |
93 ms |
10060 KB |
Output is correct |
5 |
Correct |
94 ms |
9904 KB |
Output is correct |
6 |
Correct |
94 ms |
9924 KB |
Output is correct |
7 |
Correct |
80 ms |
9924 KB |
Output is correct |
8 |
Correct |
107 ms |
9904 KB |
Output is correct |
9 |
Correct |
89 ms |
9560 KB |
Output is correct |
10 |
Correct |
123 ms |
9928 KB |
Output is correct |
11 |
Correct |
75 ms |
10056 KB |
Output is correct |
12 |
Correct |
76 ms |
10748 KB |
Output is correct |
13 |
Correct |
77 ms |
10732 KB |
Output is correct |
14 |
Correct |
88 ms |
10452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
4824 KB |
Output is correct |
2 |
Correct |
21 ms |
5716 KB |
Output is correct |
3 |
Correct |
23 ms |
7164 KB |
Output is correct |
4 |
Correct |
67 ms |
12568 KB |
Output is correct |
5 |
Correct |
77 ms |
12504 KB |
Output is correct |
6 |
Correct |
62 ms |
14016 KB |
Output is correct |
7 |
Correct |
79 ms |
14672 KB |
Output is correct |
8 |
Correct |
72 ms |
12964 KB |
Output is correct |
9 |
Correct |
77 ms |
13104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3424 KB |
Output is correct |
2 |
Correct |
16 ms |
4304 KB |
Output is correct |
3 |
Correct |
80 ms |
8600 KB |
Output is correct |
4 |
Correct |
96 ms |
9908 KB |
Output is correct |
5 |
Correct |
60 ms |
9556 KB |
Output is correct |
6 |
Correct |
80 ms |
10120 KB |
Output is correct |
7 |
Correct |
92 ms |
9576 KB |
Output is correct |
8 |
Correct |
81 ms |
9632 KB |
Output is correct |
9 |
Correct |
113 ms |
9772 KB |
Output is correct |
10 |
Correct |
84 ms |
9544 KB |
Output is correct |
11 |
Correct |
101 ms |
10376 KB |
Output is correct |
12 |
Correct |
76 ms |
11144 KB |
Output is correct |
13 |
Correct |
68 ms |
10520 KB |
Output is correct |
14 |
Correct |
80 ms |
10452 KB |
Output is correct |
15 |
Correct |
96 ms |
9908 KB |
Output is correct |
16 |
Correct |
82 ms |
9936 KB |
Output is correct |
17 |
Correct |
98 ms |
10232 KB |
Output is correct |
18 |
Correct |
82 ms |
10620 KB |
Output is correct |
19 |
Correct |
90 ms |
9560 KB |
Output is correct |
20 |
Correct |
73 ms |
11440 KB |
Output is correct |
21 |
Correct |
75 ms |
10664 KB |
Output is correct |
22 |
Correct |
81 ms |
10684 KB |
Output is correct |
23 |
Correct |
102 ms |
10344 KB |
Output is correct |
24 |
Correct |
87 ms |
10364 KB |
Output is correct |
25 |
Correct |
93 ms |
13860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
238 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
199 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |