#include<bits/stdc++.h>
#include "highway.h"
#define mp make_pair
#define pb push_back
using namespace std;
using pii = pair < int, int >;
vector < vector < pii > > to;
vector < pii > edg, ans;
vector<int> w;
int n, m, A, B;
long long L;
void bfs( int start, int startParent){
bool used[n+1];
memset( used, 0, sizeof(used) );
ans.clear();
queue < int > q;
q.push( start );
used[start] = 1;
if( startParent != -1 ) used[startParent] = 1;
while( !q.empty() ){
int sz = q.size();
while(sz--){
int u = q.front();
q.pop();
for( pii v : to[u] ){
if( used[v.first] ) continue;
q.push( v.first );
used[v.first] = 1;
ans.push_back( mp( v.second, v.first ) );
}
}
}
}
int findEnd( int start, int startParent ){
bfs( start, startParent );
fill( w.begin(), w.end(), 0 );
L = ask( w );
/*
cerr << "############\n";
cerr << "start : "<< start << ' ' << startParent << endl;
for(int i = 0 ; i < ans.size() ; i++){
cerr << ans[i].second << ' ' << ans[i].first << endl;
}*/
if( ans.empty() ) return start;
// cerr << L << endl;
long long now;
int l = 0, r = ans.size()-1;
while( l+1 < r ){
int mid = (l+r)>>1;
fill( w.begin(), w.end(), 0 );
for(int i = mid ; i <= r ; i++){
w[ans[i].first] = 1;
}
now = ask( w );
// cerr << l << ' ' << r << " : " << mid << ' ' << now << endl;
if( now > L ) l = mid;
else r = mid-1;
}
// cerr << l << ' ' << r << endl;
if( l != r ){
fill( w.begin(), w.end(), 0 );
w[ ans[l+1].first ] = 1;
now = ask( w );
if( now > L ) return ans[l+1].second;
fill( w.begin(), w.end(), 0 );
w[ ans[l].first ] = 1;
now = ask( w );
if( now > L ) return ans[l].second;
return start;
}
fill( w.begin(), w.end(), 0 );
w[ ans[l].first ] = 1;
now = ask( w );
if( now > L ) return ans[l].second;
return start;
}
int findEdge( int start ){
bfs( start, -1 );
fill( w.begin(), w.end(), 0 );
L = ask( w );
long long now;
int l = 0, r = ans.size()-1;
while( l+1 < r ){
int mid = (l+r)>>1;
fill( w.begin(), w.end(), 0 );
for(int i = mid ; i <= r ; i++){
w[ans[i].first] = 1;
}
now = ask( w );
// cerr << l << ' ' << r << " : " << mid << ' ' << now << endl;
if( now > L ) l = mid;
else r = mid-1;
}
if( l != r ){
fill( w.begin(), w.end(), 0 );
w[ ans[l].first ] = 1;
now = ask( w );
if( now > L ) return ans[l].first;
fill( w.begin(), w.end(), 0 );
w[ ans[l+1].first ] = 1;
now = ask( w );
if( now > L ) return ans[l+1].first;
return start;
}
return ans[l].first;
}
void find_pair(int N, vector<int> U, vector<int> V, int _A, int _B) {
n = N; A = _A; B = _B; m = U.size();
w.resize(m);
to.resize(n+1);
for(int i = 0 ; i < m ; i++){
to[ U[i] ].pb( mp( V[i], i ) );
to[ V[i] ].pb( mp( U[i], i ) );
edg.push_back( mp( V[i], U[i] ) );
}
int e = findEdge( 0 );
// cerr << "### " << edg[e].first << ' ' << edg[e].second << endl;
int s = findEnd( edg[e].first, edg[e].second );
int t = findEnd( edg[e].second, edg[e].first );
// cerr << "## " << s << ' ' << t << endl;
answer( s, t );
}
/*
4 3 1 3 1 3
0 1
0 2
0 3
10 9 1 5 3 9
0 1
0 2
2 9
1 3
1 4
1 5
3 6
4 7
4 8
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
308 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 |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
2 ms |
248 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
22 ms |
1336 KB |
Output is correct |
3 |
Correct |
196 ms |
9848 KB |
Output is correct |
4 |
Correct |
189 ms |
9844 KB |
Output is correct |
5 |
Correct |
226 ms |
9848 KB |
Output is correct |
6 |
Correct |
199 ms |
9872 KB |
Output is correct |
7 |
Correct |
197 ms |
9824 KB |
Output is correct |
8 |
Correct |
194 ms |
9972 KB |
Output is correct |
9 |
Correct |
193 ms |
9840 KB |
Output is correct |
10 |
Correct |
190 ms |
9960 KB |
Output is correct |
11 |
Correct |
217 ms |
9340 KB |
Output is correct |
12 |
Correct |
210 ms |
9340 KB |
Output is correct |
13 |
Correct |
202 ms |
9292 KB |
Output is correct |
14 |
Correct |
202 ms |
9332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
1272 KB |
Output is correct |
2 |
Correct |
39 ms |
2380 KB |
Output is correct |
3 |
Correct |
56 ms |
3232 KB |
Output is correct |
4 |
Correct |
154 ms |
9340 KB |
Output is correct |
5 |
Correct |
169 ms |
9336 KB |
Output is correct |
6 |
Correct |
166 ms |
9340 KB |
Output is correct |
7 |
Correct |
152 ms |
9336 KB |
Output is correct |
8 |
Correct |
169 ms |
9332 KB |
Output is correct |
9 |
Correct |
164 ms |
9332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
22 ms |
1320 KB |
Output is correct |
3 |
Correct |
144 ms |
8028 KB |
Output is correct |
4 |
Correct |
193 ms |
9840 KB |
Output is correct |
5 |
Correct |
206 ms |
9848 KB |
Output is correct |
6 |
Correct |
195 ms |
9864 KB |
Output is correct |
7 |
Correct |
191 ms |
9848 KB |
Output is correct |
8 |
Correct |
192 ms |
9896 KB |
Output is correct |
9 |
Correct |
191 ms |
9852 KB |
Output is correct |
10 |
Correct |
206 ms |
9836 KB |
Output is correct |
11 |
Correct |
199 ms |
9336 KB |
Output is correct |
12 |
Correct |
229 ms |
9340 KB |
Output is correct |
13 |
Correct |
234 ms |
9336 KB |
Output is correct |
14 |
Correct |
197 ms |
9344 KB |
Output is correct |
15 |
Correct |
188 ms |
9844 KB |
Output is correct |
16 |
Correct |
201 ms |
9844 KB |
Output is correct |
17 |
Correct |
220 ms |
9332 KB |
Output is correct |
18 |
Correct |
222 ms |
9516 KB |
Output is correct |
19 |
Correct |
190 ms |
9864 KB |
Output is correct |
20 |
Correct |
216 ms |
9332 KB |
Output is correct |
21 |
Correct |
146 ms |
10200 KB |
Output is correct |
22 |
Correct |
172 ms |
10216 KB |
Output is correct |
23 |
Correct |
175 ms |
9968 KB |
Output is correct |
24 |
Correct |
179 ms |
9972 KB |
Output is correct |
25 |
Correct |
180 ms |
9424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1468 KB |
Output is correct |
2 |
Correct |
24 ms |
1428 KB |
Output is correct |
3 |
Correct |
209 ms |
10308 KB |
Output is correct |
4 |
Correct |
230 ms |
10784 KB |
Output is correct |
5 |
Incorrect |
282 ms |
11948 KB |
Output is incorrect: {s, t} is wrong. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1416 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |