#include "highway.h"
#include <vector>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
typedef long long ll;
const int maxn=1e5, maxm=2e5;
int m, a, b, n;
vector < int > ms[maxn];
vector < int > ms1[maxn];
pair < int, int > edge[maxm];
vector < int > Q;
ll poc;
int nadji(int l, int r){
if(l==r-1){
return l;
}
int mid=(l+r)/2;
for(int i=l; i<mid; i++){
Q[i]=1;
}
ll val=ask(Q);
if(val>poc){
for(int i=l; i<mid; i++){
Q[i]=0;
}
return nadji(l, mid);
}
else{
return nadji(mid, r);
}
}
int dist[2][maxn];
void bfs(int x, int ind){
queue < int > q;
q.push(x);
dist[ind][x]=0;
while(!q.empty()){
x=q.front();
q.pop();
for(int i=0; i<(int)ms[x].size(); i++){
if(dist[ind][ms[x][i]]==-1){
dist[ind][ms[x][i]]=dist[ind][x]+1;
q.push(ms[x][i]);
}
}
}
}
int col[maxn];
vector < int > sta[maxn];
vector < int > sta1[maxn];
int bio[maxn];
void bfs1(int x){
queue < int > q;
q.push(x);
memset(bio, -1, sizeof(bio));
bio[x]=0;
while(!q.empty()){
x=q.front();
q.pop();
for(int i=0; i<(int)ms[x].size(); i++){
if(bio[ms[x][i]]==-1 && col[ms[x][i]]==col[x]){
bio[ms[x][i]]=bio[x]+1;
sta[x].push_back(ms[x][i]);
sta1[x].push_back(ms1[x][i]);
// cout << x << ' ' << ms[x][i] << ' ' << ms1[x][i] << endl;
sta[ms[x][i]].push_back(x);
sta1[ms[x][i]].push_back(ms1[x][i]);
q.push(ms[x][i]);
}
}
}
}
vector < int > red;
void dfs(int x, int prosl){
for(int i=0; i<(int)sta[x].size(); i++){
if(sta[x][i]!=prosl){
red.push_back(sta1[x][i]);
dfs(sta[x][i], x);
}
}
}
ll maksi;
int rijesi(int l, int r){
if(l==r-1){
return l;
}
int mid=(l+r)/2;
for(int i=l; i<mid; i++){
if(red[i]==-1){
continue;
}
Q[red[i]]=1;
}
// cout << "querijam " << l << ' ' << r << endl;
/* for(int i=0; i<Q.size(); i++){
cout << Q[i] << ' ';
}
cout << endl;*/
if(ask(Q)==maksi){
for(int i=l; i<mid; i++){
if(red[i]==-1){
continue;
}
Q[red[i]]=0;
}
// cout << "ima" << endl;
return rijesi(l, mid);
}
else{
return rijesi(mid, r);
}
}
void find_pair(int N, vector<int> u, vector<int> v, int A, int B) {
m = u.size();
n=N;
a=A;
b=B;
for(int i=0; i<m; i++){
edge[i]={u[i], v[i]};
ms[u[i]].push_back(v[i]);
ms[v[i]].push_back(u[i]);
ms1[u[i]].push_back(i);
ms1[v[i]].push_back(i);
}
Q.resize(m, 0);
poc=ask(Q);
int x=nadji(0, m);
memset(dist[0], -1, sizeof(dist[0]));
memset(dist[1], -1, sizeof(dist[1]));
bfs(edge[x].first, 0);
bfs(edge[x].second, 1);
for(int i=0; i<n; i++){
if(dist[0][i]<dist[1][i]){
col[i]=1;
}
}
red.push_back(-1);
bfs1(edge[x].first);
dfs(edge[x].first, -1);
for(int i=1; i<(int)red.size(); i++){
Q[red[i]]=1;
}
maksi=ask(Q);
for(int i=1; i<(int)red.size(); i++){
Q[red[i]]=0;
}
/* cout << "red ";
for(int i=0; i<(int)red.size(); i++){
cout << red[i] << ' ';
}
cout << endl;*/
int y=red[rijesi(0, red.size())];
int sol1, sol2;
if(y==-1){
sol1=edge[x].first;
}
else if(bio[edge[y].first]>bio[edge[y].second]){
sol1=edge[y].first;
}
else{
sol1=edge[y].second;
}
/* for(int i=0; i<n; i++){
sta[i].clear();
sta1[i].clear();
}*/
bfs1(edge[x].second);
red.clear();
red.push_back(-1);
dfs(edge[x].second, -1);
for(int i=1; i<(int)red.size(); i++){
Q[red[i]]=1;
}
maksi=ask(Q);
/* for(int i=0; i<Q.size(); i++){
cout << Q[i] << ' ';
}
cout << endl;*/
for(int i=1; i<(int)red.size(); i++){
Q[red[i]]=0;
}
/* cout << "red2 ";
for(int i=0; i<(int)red.size(); i++){
cout << red[i] << ' ';
}
cout << endl;*/
y=red[rijesi(0, red.size())];
// cout << maksi << endl;
// cout << y << endl;
if(y==-1){
sol2=edge[x].second;
}
else if(bio[edge[y].first]>bio[edge[y].second]){
sol2=edge[y].first;
}
else{
sol2=edge[y].second;
}
// cout << sol1 << ' ' << sol2 << ' ' << x << endl;
answer(sol1, sol2);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
10824 KB |
Output is correct |
2 |
Correct |
10 ms |
10772 KB |
Output is correct |
3 |
Correct |
10 ms |
10868 KB |
Output is correct |
4 |
Correct |
7 ms |
10824 KB |
Output is correct |
5 |
Correct |
8 ms |
10824 KB |
Output is correct |
6 |
Correct |
7 ms |
10864 KB |
Output is correct |
7 |
Correct |
9 ms |
10824 KB |
Output is correct |
8 |
Correct |
8 ms |
10824 KB |
Output is correct |
9 |
Correct |
7 ms |
10872 KB |
Output is correct |
10 |
Correct |
9 ms |
10952 KB |
Output is correct |
11 |
Correct |
7 ms |
10792 KB |
Output is correct |
12 |
Correct |
8 ms |
10824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
10948 KB |
Output is correct |
2 |
Correct |
30 ms |
12572 KB |
Output is correct |
3 |
Correct |
329 ms |
26116 KB |
Output is correct |
4 |
Correct |
267 ms |
25876 KB |
Output is correct |
5 |
Correct |
290 ms |
25956 KB |
Output is correct |
6 |
Correct |
240 ms |
25544 KB |
Output is correct |
7 |
Correct |
308 ms |
25924 KB |
Output is correct |
8 |
Correct |
261 ms |
25936 KB |
Output is correct |
9 |
Correct |
256 ms |
25992 KB |
Output is correct |
10 |
Correct |
277 ms |
25936 KB |
Output is correct |
11 |
Correct |
292 ms |
26256 KB |
Output is correct |
12 |
Correct |
328 ms |
27208 KB |
Output is correct |
13 |
Correct |
320 ms |
27000 KB |
Output is correct |
14 |
Correct |
265 ms |
26752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
12976 KB |
Output is correct |
2 |
Correct |
46 ms |
14968 KB |
Output is correct |
3 |
Correct |
61 ms |
17288 KB |
Output is correct |
4 |
Correct |
184 ms |
28440 KB |
Output is correct |
5 |
Correct |
184 ms |
28488 KB |
Output is correct |
6 |
Correct |
186 ms |
29468 KB |
Output is correct |
7 |
Correct |
174 ms |
30560 KB |
Output is correct |
8 |
Correct |
154 ms |
28932 KB |
Output is correct |
9 |
Correct |
178 ms |
29304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
10952 KB |
Output is correct |
2 |
Correct |
30 ms |
12460 KB |
Output is correct |
3 |
Correct |
180 ms |
22552 KB |
Output is correct |
4 |
Correct |
297 ms |
25668 KB |
Output is correct |
5 |
Correct |
246 ms |
25984 KB |
Output is correct |
6 |
Correct |
288 ms |
25680 KB |
Output is correct |
7 |
Correct |
244 ms |
26032 KB |
Output is correct |
8 |
Correct |
279 ms |
25984 KB |
Output is correct |
9 |
Correct |
273 ms |
25700 KB |
Output is correct |
10 |
Correct |
260 ms |
25992 KB |
Output is correct |
11 |
Correct |
326 ms |
26616 KB |
Output is correct |
12 |
Correct |
297 ms |
27400 KB |
Output is correct |
13 |
Correct |
334 ms |
26892 KB |
Output is correct |
14 |
Correct |
284 ms |
26716 KB |
Output is correct |
15 |
Correct |
282 ms |
25648 KB |
Output is correct |
16 |
Correct |
276 ms |
25540 KB |
Output is correct |
17 |
Correct |
325 ms |
26536 KB |
Output is correct |
18 |
Correct |
318 ms |
27092 KB |
Output is correct |
19 |
Correct |
267 ms |
25952 KB |
Output is correct |
20 |
Correct |
253 ms |
27624 KB |
Output is correct |
21 |
Correct |
205 ms |
27184 KB |
Output is correct |
22 |
Correct |
219 ms |
27468 KB |
Output is correct |
23 |
Correct |
185 ms |
26788 KB |
Output is correct |
24 |
Correct |
242 ms |
27060 KB |
Output is correct |
25 |
Correct |
328 ms |
30344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
27 ms |
12528 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
28 ms |
12520 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |