#include "highway.h"
//#include "grader.cpp"
#include <set>
#include <queue>
#include <vector>
#include <assert.h>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXLog = 18;
int n;
vector <pair <int, int>> graph[MAXN];
long long base;
vector <int> edgeInd;
int getFirstEdge()
{
vector <int> v;
v.assign(edgeInd.size(), 0);
int ind = 0;
base = ask(v);
int l = 0, r = edgeInd.size() - 1, mid;
while(l!=r)
{
mid = (l+r)/2;
for(int i = 0;i<edgeInd.size();i++)
{
if(edgeInd[i]<=mid) v[i] = 1;
else v[i] = 0;
}
if(ask(v)!=base) r = mid;
else l = mid + 1;
}
return l;
}
int getLastEdge(int addedEdges)
{
vector <int> v;
v.assign(edgeInd.size(), 0);
int l = -1, r = addedEdges - 1, mid;
while(l!=r)
{
mid = (l+r+1)/2;
for(int i = 0;i<edgeInd.size();i++)
{
if(edgeInd[i]>=mid) v[i] = 1;
else v[i] = 0;
}
if(ask(v)!=base) l = mid;
else r = mid - 1;
}
return l;
}
vector <int> getDist(int x)
{
queue <int> q;
vector <int> dist;
dist.assign(n, -1);
q.push(x);
dist[x] = 0;
while(q.empty()==false)
{
x = q.front();
q.pop();
for(pair <int, int> item: graph[x])
{
if(dist[item.first]==-1)
{
dist[item.first] = dist[x] + 1;
q.push(item.first);
}
}
}
return dist;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
//cout << '\n';
n = N;
for(int i = 0;i<U.size();i++)
{
graph[ U[i] ].push_back({V[i], i});
graph[ V[i] ].push_back({U[i], i});
}
for(int i = 0;i<U.size();i++)
{
edgeInd.push_back(i);
}
int e = getFirstEdge();
int nodes[] = {U[e], V[e]};
//cout << nodes[0] << " " << nodes[1] << '\n';
vector <int> dist[2];
dist[0] = getDist(nodes[0]);
dist[1] = getDist(nodes[1]);
int ans[2];
for(int rep = 0;rep<2;rep++)
{
//cout << " ----- " << rep << " ------ " << '\n';
int addedEdges = 0;
for(int i = 0;i<edgeInd.size();i++) edgeInd[i] = -1;
queue <int> q;
vector <int> d(n, -1);
vector <int> vertexOfEdge(U.size(), -1);
q.push(nodes[rep]);
d[ nodes[rep] ] = 0;
while(q.empty()==false)
{
int x = q.front();
q.pop();
//cout << x << " -> " << d[x] << '\n';
for(pair <int, int> item: graph[x])
{
if(dist[rep][item.first]<dist[rep^1][item.first])
{
if(d[item.first]==-1)
{
d[item.first] = d[x] + 1;
q.push(item.first);
edgeInd[item.second] = addedEdges;
vertexOfEdge[addedEdges] = item.first;
//cout << item.second << ": " << addedEdges << '\n';
addedEdges++;
}
else if(d[item.first]==d[x]+1)
{
edgeInd[item.second] = U.size() + 1;
}
}
else if(item.second!=e)
{
edgeInd[item.second] = U.size() + 1;
}
}
}
int lastE = getLastEdge(addedEdges);
//cout << lastE << '\n';
ans[rep] = ((lastE==-1)?nodes[rep]:vertexOfEdge[lastE]);
}
//cout << ans[0] << " -- " << ans[1] << '\n';
answer(ans[0], ans[1]);
}
/*
4 4
1 3
3 2
0 1
0 2
0 3
1 2
*/
Compilation message
highway.cpp: In function 'int getFirstEdge()':
highway.cpp:33:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i = 0;i<edgeInd.size();i++)
| ~^~~~~~~~~~~~~~~
highway.cpp:26:9: warning: unused variable 'ind' [-Wunused-variable]
26 | int ind = 0;
| ^~~
highway.cpp: In function 'int getLastEdge(int)':
highway.cpp:55:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = 0;i<edgeInd.size();i++)
| ~^~~~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:100:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int i = 0;i<U.size();i++)
| ~^~~~~~~~~
highway.cpp:105:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(int i = 0;i<U.size();i++)
| ~^~~~~~~~~
highway.cpp:124:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int i = 0;i<edgeInd.size();i++) edgeInd[i] = -1;
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
16 ms |
3456 KB |
Output is correct |
3 |
Correct |
156 ms |
9684 KB |
Output is correct |
4 |
Correct |
158 ms |
9680 KB |
Output is correct |
5 |
Correct |
171 ms |
9756 KB |
Output is correct |
6 |
Correct |
138 ms |
9672 KB |
Output is correct |
7 |
Correct |
206 ms |
9684 KB |
Output is correct |
8 |
Correct |
206 ms |
9684 KB |
Output is correct |
9 |
Correct |
197 ms |
9688 KB |
Output is correct |
10 |
Correct |
161 ms |
9772 KB |
Output is correct |
11 |
Correct |
176 ms |
9236 KB |
Output is correct |
12 |
Correct |
165 ms |
9092 KB |
Output is correct |
13 |
Correct |
167 ms |
9220 KB |
Output is correct |
14 |
Correct |
183 ms |
9152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3456 KB |
Output is correct |
2 |
Correct |
30 ms |
4252 KB |
Output is correct |
3 |
Correct |
53 ms |
4936 KB |
Output is correct |
4 |
Correct |
110 ms |
9244 KB |
Output is correct |
5 |
Correct |
166 ms |
9084 KB |
Output is correct |
6 |
Correct |
119 ms |
9288 KB |
Output is correct |
7 |
Correct |
131 ms |
9092 KB |
Output is correct |
8 |
Correct |
121 ms |
9084 KB |
Output is correct |
9 |
Correct |
120 ms |
9088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Correct |
16 ms |
3456 KB |
Output is correct |
3 |
Correct |
145 ms |
8148 KB |
Output is correct |
4 |
Correct |
190 ms |
9664 KB |
Output is correct |
5 |
Correct |
208 ms |
9664 KB |
Output is correct |
6 |
Correct |
160 ms |
9656 KB |
Output is correct |
7 |
Correct |
154 ms |
9688 KB |
Output is correct |
8 |
Correct |
154 ms |
9764 KB |
Output is correct |
9 |
Correct |
165 ms |
9664 KB |
Output is correct |
10 |
Correct |
227 ms |
9676 KB |
Output is correct |
11 |
Correct |
235 ms |
9096 KB |
Output is correct |
12 |
Correct |
227 ms |
9104 KB |
Output is correct |
13 |
Correct |
196 ms |
9096 KB |
Output is correct |
14 |
Correct |
227 ms |
9136 KB |
Output is correct |
15 |
Correct |
155 ms |
9684 KB |
Output is correct |
16 |
Correct |
188 ms |
9724 KB |
Output is correct |
17 |
Correct |
192 ms |
9232 KB |
Output is correct |
18 |
Correct |
208 ms |
9116 KB |
Output is correct |
19 |
Correct |
178 ms |
9700 KB |
Output is correct |
20 |
Correct |
203 ms |
9084 KB |
Output is correct |
21 |
Correct |
162 ms |
10184 KB |
Output is correct |
22 |
Correct |
156 ms |
10208 KB |
Output is correct |
23 |
Correct |
182 ms |
9968 KB |
Output is correct |
24 |
Correct |
143 ms |
9888 KB |
Output is correct |
25 |
Correct |
167 ms |
9196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3448 KB |
Output is correct |
2 |
Correct |
20 ms |
3604 KB |
Output is correct |
3 |
Correct |
176 ms |
10168 KB |
Output is correct |
4 |
Correct |
214 ms |
10632 KB |
Output is correct |
5 |
Correct |
290 ms |
11768 KB |
Output is correct |
6 |
Correct |
310 ms |
11756 KB |
Output is correct |
7 |
Correct |
261 ms |
11732 KB |
Output is correct |
8 |
Correct |
249 ms |
11748 KB |
Output is correct |
9 |
Correct |
169 ms |
9656 KB |
Output is correct |
10 |
Correct |
191 ms |
10112 KB |
Output is correct |
11 |
Correct |
188 ms |
10396 KB |
Output is correct |
12 |
Correct |
221 ms |
11416 KB |
Output is correct |
13 |
Correct |
305 ms |
11724 KB |
Output is correct |
14 |
Correct |
295 ms |
11792 KB |
Output is correct |
15 |
Correct |
311 ms |
11732 KB |
Output is correct |
16 |
Correct |
214 ms |
10700 KB |
Output is correct |
17 |
Correct |
190 ms |
10204 KB |
Output is correct |
18 |
Correct |
143 ms |
10416 KB |
Output is correct |
19 |
Correct |
137 ms |
10300 KB |
Output is correct |
20 |
Correct |
186 ms |
10348 KB |
Output is correct |
21 |
Correct |
302 ms |
11868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
3448 KB |
Output is correct |
2 |
Correct |
20 ms |
3620 KB |
Output is correct |
3 |
Correct |
247 ms |
10132 KB |
Output is correct |
4 |
Correct |
201 ms |
10700 KB |
Output is correct |
5 |
Correct |
265 ms |
10756 KB |
Output is correct |
6 |
Correct |
233 ms |
11764 KB |
Output is correct |
7 |
Correct |
180 ms |
10152 KB |
Output is correct |
8 |
Correct |
191 ms |
10408 KB |
Output is correct |
9 |
Correct |
216 ms |
10720 KB |
Output is correct |
10 |
Correct |
316 ms |
11828 KB |
Output is correct |
11 |
Correct |
239 ms |
11728 KB |
Output is correct |
12 |
Correct |
238 ms |
11924 KB |
Output is correct |
13 |
Correct |
177 ms |
10444 KB |
Output is correct |
14 |
Correct |
177 ms |
10104 KB |
Output is correct |
15 |
Correct |
237 ms |
10468 KB |
Output is correct |
16 |
Correct |
166 ms |
10324 KB |
Output is correct |
17 |
Correct |
243 ms |
10476 KB |
Output is correct |
18 |
Correct |
179 ms |
10288 KB |
Output is correct |
19 |
Correct |
304 ms |
11396 KB |
Output is correct |
20 |
Correct |
306 ms |
11524 KB |
Output is correct |
21 |
Correct |
316 ms |
11832 KB |
Output is correct |
22 |
Correct |
298 ms |
11872 KB |
Output is correct |
23 |
Correct |
261 ms |
11804 KB |
Output is correct |
24 |
Correct |
263 ms |
11736 KB |
Output is correct |
25 |
Correct |
312 ms |
11824 KB |
Output is correct |
26 |
Correct |
310 ms |
11740 KB |
Output is correct |
27 |
Correct |
170 ms |
10340 KB |
Output is correct |
28 |
Correct |
152 ms |
10272 KB |
Output is correct |
29 |
Correct |
129 ms |
10624 KB |
Output is correct |
30 |
Correct |
175 ms |
10376 KB |
Output is correct |
31 |
Correct |
134 ms |
10368 KB |
Output is correct |
32 |
Correct |
132 ms |
10332 KB |
Output is correct |
33 |
Correct |
148 ms |
10616 KB |
Output is correct |
34 |
Correct |
149 ms |
10292 KB |
Output is correct |
35 |
Correct |
140 ms |
10356 KB |
Output is correct |
36 |
Correct |
149 ms |
10208 KB |
Output is correct |
37 |
Correct |
150 ms |
10648 KB |
Output is correct |
38 |
Correct |
153 ms |
10388 KB |
Output is correct |
39 |
Correct |
229 ms |
11772 KB |
Output is correct |
40 |
Correct |
281 ms |
11872 KB |
Output is correct |
41 |
Correct |
225 ms |
11836 KB |
Output is correct |
42 |
Correct |
253 ms |
11852 KB |
Output is correct |