#include "bits/stdc++.h"
#include "highway.h"
using namespace std;
#define int long long
pair<int,int> p[100001];
int dep[100001];
vector<pair<int,int>> adj[100001];
void dfs(int i){
queue<int> q;
q.push(i);
dep[i] = 1;
p[i] = {i,-1};
while(!q.empty()){
int f = q.front();q.pop();
for(auto j:adj[f]){
if(dep[j.first]==0){
dep[j.first] = dep[f]+1;
p[j.first] = {f,j.second};
q.push(j.first);
}
}
}
}
void find_pair(int32_t N, vector<int32_t> U, vector<int32_t> V, int32_t A, int32_t B){
int m = U.size();
int n = N;
vector<int32_t> as(m,0);
int len = ask(as);
for(int i = 0;i<U.size();i++){
adj[U[i]].push_back({V[i],i});
adj[V[i]].push_back({U[i],i});
}
int l = 0 ,r = n-1 , ans = 0;
while(l<=r){
int mid = (l+r)/2;
vector<int32_t> as(m,0);
for(int i = mid+1;i<n;i++){
for(auto j:adj[i]){
as[j.second] = 1;
}
}
if(ask(as)==len){
ans = mid;
r = mid-1;
}else l = mid+1;
}
dfs(ans);
vector<pair<int,int>> v;
for(int i = 0;i<N;i++){
v.push_back({dep[i],i});
}
sort(v.begin(),v.end());
l = 1 , r = n-1 ;int ans2 = 0;
while(l<=r){
int mid = (l+r)/2;
vector<int32_t> as(m,1);
for(int i = 1;i<=mid;i++){
as[p[v[i].second].second] =0 ;
}
if(ask(as)==len){
ans2 = mid;
r = mid-1;
}else l = mid+1;
}
int a = v[ans2].second;
l = 0 , r = ans2-1 ;
int ans3 = 0;
while(l<=r){
int mid = (l+r)/2;
vector<int32_t> as(m,1);
for(int i = 1;i<=mid;i++){
as[p[v[i].second].second] = 0;
}
int f = a;
while(p[f].second!=-1){
as[p[f].second] = 0;
f = p[f].first;
}
if(ask(as)==len){
ans3 = mid;
r = mid-1;
}else l = mid+1;
}
int b = v[ans3].second;
answer(a,b);
}
Compilation message
highway.cpp: In function 'void find_pair(int32_t, std::vector<int>, std::vector<int>, int32_t, int32_t)':
highway.cpp:31:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i = 0;i<U.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2904 KB |
Output is correct |
2 |
Correct |
8 ms |
3928 KB |
Output is correct |
3 |
Correct |
89 ms |
13692 KB |
Output is correct |
4 |
Correct |
91 ms |
13800 KB |
Output is correct |
5 |
Correct |
99 ms |
13908 KB |
Output is correct |
6 |
Correct |
80 ms |
13884 KB |
Output is correct |
7 |
Correct |
81 ms |
13836 KB |
Output is correct |
8 |
Correct |
82 ms |
13700 KB |
Output is correct |
9 |
Correct |
74 ms |
13680 KB |
Output is correct |
10 |
Correct |
103 ms |
13904 KB |
Output is correct |
11 |
Correct |
83 ms |
13708 KB |
Output is correct |
12 |
Correct |
83 ms |
13728 KB |
Output is correct |
13 |
Correct |
88 ms |
13788 KB |
Output is correct |
14 |
Correct |
91 ms |
13712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3928 KB |
Output is correct |
2 |
Correct |
14 ms |
5044 KB |
Output is correct |
3 |
Correct |
20 ms |
6100 KB |
Output is correct |
4 |
Correct |
64 ms |
13380 KB |
Output is correct |
5 |
Correct |
73 ms |
13316 KB |
Output is correct |
6 |
Correct |
65 ms |
13292 KB |
Output is correct |
7 |
Correct |
74 ms |
13396 KB |
Output is correct |
8 |
Correct |
63 ms |
13240 KB |
Output is correct |
9 |
Correct |
76 ms |
13460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2904 KB |
Output is correct |
2 |
Correct |
8 ms |
3928 KB |
Output is correct |
3 |
Correct |
59 ms |
11632 KB |
Output is correct |
4 |
Correct |
77 ms |
13664 KB |
Output is correct |
5 |
Correct |
68 ms |
13688 KB |
Output is correct |
6 |
Correct |
85 ms |
13652 KB |
Output is correct |
7 |
Correct |
76 ms |
13816 KB |
Output is correct |
8 |
Correct |
78 ms |
13640 KB |
Output is correct |
9 |
Correct |
93 ms |
13952 KB |
Output is correct |
10 |
Correct |
84 ms |
13808 KB |
Output is correct |
11 |
Correct |
101 ms |
13800 KB |
Output is correct |
12 |
Correct |
96 ms |
13728 KB |
Output is correct |
13 |
Correct |
95 ms |
13724 KB |
Output is correct |
14 |
Correct |
91 ms |
13868 KB |
Output is correct |
15 |
Correct |
74 ms |
13676 KB |
Output is correct |
16 |
Correct |
72 ms |
13812 KB |
Output is correct |
17 |
Correct |
96 ms |
13728 KB |
Output is correct |
18 |
Correct |
90 ms |
13708 KB |
Output is correct |
19 |
Correct |
78 ms |
13696 KB |
Output is correct |
20 |
Correct |
79 ms |
13744 KB |
Output is correct |
21 |
Correct |
77 ms |
13856 KB |
Output is correct |
22 |
Correct |
73 ms |
13836 KB |
Output is correct |
23 |
Correct |
75 ms |
14056 KB |
Output is correct |
24 |
Correct |
83 ms |
13864 KB |
Output is correct |
25 |
Correct |
104 ms |
13828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4184 KB |
Output is correct |
2 |
Correct |
10 ms |
4184 KB |
Output is correct |
3 |
Correct |
87 ms |
14544 KB |
Output is correct |
4 |
Correct |
104 ms |
15216 KB |
Output is correct |
5 |
Correct |
119 ms |
16816 KB |
Output is correct |
6 |
Correct |
118 ms |
16552 KB |
Output is correct |
7 |
Correct |
104 ms |
16752 KB |
Output is correct |
8 |
Correct |
118 ms |
16640 KB |
Output is correct |
9 |
Correct |
89 ms |
12056 KB |
Output is correct |
10 |
Correct |
83 ms |
13096 KB |
Output is correct |
11 |
Correct |
97 ms |
13580 KB |
Output is correct |
12 |
Correct |
105 ms |
16248 KB |
Output is correct |
13 |
Correct |
121 ms |
16600 KB |
Output is correct |
14 |
Correct |
120 ms |
16712 KB |
Output is correct |
15 |
Correct |
116 ms |
16764 KB |
Output is correct |
16 |
Correct |
105 ms |
14552 KB |
Output is correct |
17 |
Correct |
84 ms |
13520 KB |
Output is correct |
18 |
Correct |
86 ms |
13884 KB |
Output is correct |
19 |
Correct |
71 ms |
13588 KB |
Output is correct |
20 |
Correct |
79 ms |
13820 KB |
Output is correct |
21 |
Correct |
115 ms |
16724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
4184 KB |
Output is correct |
2 |
Correct |
10 ms |
4184 KB |
Output is correct |
3 |
Correct |
90 ms |
14720 KB |
Output is correct |
4 |
Correct |
98 ms |
14836 KB |
Output is correct |
5 |
Correct |
105 ms |
15208 KB |
Output is correct |
6 |
Correct |
118 ms |
16672 KB |
Output is correct |
7 |
Correct |
83 ms |
14516 KB |
Output is correct |
8 |
Correct |
90 ms |
14908 KB |
Output is correct |
9 |
Correct |
89 ms |
15196 KB |
Output is correct |
10 |
Correct |
110 ms |
16808 KB |
Output is correct |
11 |
Correct |
111 ms |
16820 KB |
Output is correct |
12 |
Correct |
107 ms |
16836 KB |
Output is correct |
13 |
Correct |
102 ms |
13680 KB |
Output is correct |
14 |
Correct |
94 ms |
13024 KB |
Output is correct |
15 |
Correct |
94 ms |
13556 KB |
Output is correct |
16 |
Correct |
82 ms |
13108 KB |
Output is correct |
17 |
Correct |
104 ms |
13684 KB |
Output is correct |
18 |
Correct |
84 ms |
13104 KB |
Output is correct |
19 |
Correct |
118 ms |
16200 KB |
Output is correct |
20 |
Correct |
129 ms |
16428 KB |
Output is correct |
21 |
Correct |
115 ms |
16800 KB |
Output is correct |
22 |
Partially correct |
118 ms |
16676 KB |
Output is partially correct |
23 |
Correct |
137 ms |
16672 KB |
Output is correct |
24 |
Correct |
108 ms |
16884 KB |
Output is correct |
25 |
Correct |
116 ms |
16656 KB |
Output is correct |
26 |
Correct |
109 ms |
16660 KB |
Output is correct |
27 |
Correct |
80 ms |
13640 KB |
Output is correct |
28 |
Correct |
88 ms |
13592 KB |
Output is correct |
29 |
Partially correct |
81 ms |
14328 KB |
Output is partially correct |
30 |
Correct |
76 ms |
13836 KB |
Output is correct |
31 |
Correct |
75 ms |
13492 KB |
Output is correct |
32 |
Correct |
80 ms |
13576 KB |
Output is correct |
33 |
Correct |
80 ms |
14164 KB |
Output is correct |
34 |
Correct |
73 ms |
13936 KB |
Output is correct |
35 |
Correct |
80 ms |
13536 KB |
Output is correct |
36 |
Correct |
82 ms |
13464 KB |
Output is correct |
37 |
Correct |
75 ms |
14128 KB |
Output is correct |
38 |
Correct |
86 ms |
13964 KB |
Output is correct |
39 |
Correct |
108 ms |
16888 KB |
Output is correct |
40 |
Correct |
130 ms |
16704 KB |
Output is correct |
41 |
Correct |
126 ms |
16756 KB |
Output is correct |
42 |
Correct |
107 ms |
16824 KB |
Output is correct |