#include "highway.h"
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=300050;
const int mxM=10000;
const int mxK=60;
const ll INF=1e18;
int N, M;
vector <int> adj[mxN];
vector <pii> E;
ll val0;
int S1, S2;
int dist[mxN][2];
int col[mxN];
vector <int> ct[2];
vector <int> par[mxN];
int ans[2];
void init(int n, vector <int> u, vector <int> v, int a, int b){
N=n;
M=u.size();
for(int i=0;i<M;i++){
int t1=u[i], t2=v[i];
adj[t1].push_back(t2);
adj[t2].push_back(t1);
E.emplace_back(t1, t2);
}
}
void find_edge(){
vector <int> w(M);
val0=ask(w);
int s=0, e=M-1;
while(s!=e){
int mid=(s+e)/2;
for(int i=0;i<M;i++) w[i]=((s<=i && i<=mid) ? 1 : 0);
ll valb=ask(w);
if(valb>val0) e=mid;
else s=mid+1;
}
S1=E[s].fi, S2=E[s].se;
}
void bfs(int st, int idx){
for(int i=0;i<N;i++) dist[i][idx]=-1;
queue <int> que;
que.push(st);
dist[st][idx]=0;
while(que.size()){
int now=que.front();
que.pop();
for(int x : adj[now]) if(dist[x][idx]==-1){
dist[x][idx]=dist[now][idx]+1;
que.push(x);
}
}
}
void classify_vertex(){
for(int i=0;i<N;i++){
if(dist[i][0]==dist[i][1]){
col[i]=-1;
continue;
}
if(dist[i][0]<dist[i][1]) ct[0].push_back(i), col[i]=0;
else ct[1].push_back(i), col[i]=1;
}
for(int i=0;i<M;i++){
int a=E[i].fi, b=E[i].se;
if(col[a]==-1 || col[b]==-1 || col[a]!=col[b]) continue;
int c=col[a];
if(dist[a][c]==dist[b][c]) continue;
if(dist[a][c]<dist[b][c]) swap(a, b);
par[a].push_back(i);
}
for(int i=0;i<M;i++) if(E[i]==pii(S1, S2) || E[i]==pii(S2, S1)) par[S1].push_back(i), par[S2].push_back(i);
}
void find_vertex(int idx){
sort(all(ct[idx]), [&](int a, int b){return dist[a][idx]>dist[b][idx];});
int s=0, e=ct[idx].size()-1;
while(s!=e){
int mid=(s+e)/2;
vector <int> w(M);
for(int i=0;i<=mid;i++) for(int x : par[ct[idx][i]]) w[x]=1;
ll valw=ask(w);
if(valw>val0) e=mid;
else s=mid+1;
}
ans[idx]=ct[idx][s];
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B) {
init(n, U, V, A, B);
find_edge();
bfs(S1, 0);
bfs(S2, 1);
classify_vertex();
find_vertex(0);
find_vertex(1);
answer(ans[0], ans[1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
14424 KB |
Output is correct |
2 |
Correct |
6 ms |
14424 KB |
Output is correct |
3 |
Correct |
6 ms |
14424 KB |
Output is correct |
4 |
Correct |
6 ms |
14384 KB |
Output is correct |
5 |
Correct |
6 ms |
14424 KB |
Output is correct |
6 |
Correct |
6 ms |
14548 KB |
Output is correct |
7 |
Correct |
6 ms |
14424 KB |
Output is correct |
8 |
Correct |
6 ms |
14424 KB |
Output is correct |
9 |
Correct |
7 ms |
14424 KB |
Output is correct |
10 |
Correct |
6 ms |
14424 KB |
Output is correct |
11 |
Correct |
5 ms |
14424 KB |
Output is correct |
12 |
Correct |
5 ms |
14424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
14424 KB |
Output is correct |
2 |
Correct |
14 ms |
15468 KB |
Output is correct |
3 |
Correct |
110 ms |
24460 KB |
Output is correct |
4 |
Correct |
105 ms |
24168 KB |
Output is correct |
5 |
Correct |
103 ms |
24172 KB |
Output is correct |
6 |
Correct |
97 ms |
24176 KB |
Output is correct |
7 |
Correct |
111 ms |
24164 KB |
Output is correct |
8 |
Correct |
108 ms |
24408 KB |
Output is correct |
9 |
Correct |
105 ms |
24180 KB |
Output is correct |
10 |
Correct |
104 ms |
24160 KB |
Output is correct |
11 |
Correct |
123 ms |
24116 KB |
Output is correct |
12 |
Correct |
134 ms |
24116 KB |
Output is correct |
13 |
Correct |
115 ms |
24368 KB |
Output is correct |
14 |
Correct |
112 ms |
24068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
15612 KB |
Output is correct |
2 |
Correct |
21 ms |
16596 KB |
Output is correct |
3 |
Correct |
30 ms |
17696 KB |
Output is correct |
4 |
Correct |
78 ms |
24064 KB |
Output is correct |
5 |
Correct |
76 ms |
24068 KB |
Output is correct |
6 |
Correct |
96 ms |
24056 KB |
Output is correct |
7 |
Correct |
94 ms |
24072 KB |
Output is correct |
8 |
Correct |
94 ms |
24076 KB |
Output is correct |
9 |
Correct |
77 ms |
24092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14424 KB |
Output is correct |
2 |
Correct |
16 ms |
15472 KB |
Output is correct |
3 |
Correct |
82 ms |
22048 KB |
Output is correct |
4 |
Correct |
111 ms |
24164 KB |
Output is correct |
5 |
Correct |
105 ms |
24168 KB |
Output is correct |
6 |
Correct |
108 ms |
24164 KB |
Output is correct |
7 |
Correct |
105 ms |
24168 KB |
Output is correct |
8 |
Correct |
98 ms |
24156 KB |
Output is correct |
9 |
Correct |
118 ms |
24100 KB |
Output is correct |
10 |
Correct |
111 ms |
24172 KB |
Output is correct |
11 |
Correct |
119 ms |
24272 KB |
Output is correct |
12 |
Correct |
116 ms |
24080 KB |
Output is correct |
13 |
Correct |
118 ms |
24108 KB |
Output is correct |
14 |
Correct |
114 ms |
24060 KB |
Output is correct |
15 |
Correct |
104 ms |
24180 KB |
Output is correct |
16 |
Correct |
108 ms |
24168 KB |
Output is correct |
17 |
Correct |
131 ms |
24076 KB |
Output is correct |
18 |
Correct |
110 ms |
24208 KB |
Output is correct |
19 |
Correct |
106 ms |
24164 KB |
Output is correct |
20 |
Correct |
106 ms |
24072 KB |
Output is correct |
21 |
Correct |
94 ms |
24644 KB |
Output is correct |
22 |
Correct |
95 ms |
24440 KB |
Output is correct |
23 |
Correct |
97 ms |
24432 KB |
Output is correct |
24 |
Correct |
97 ms |
24392 KB |
Output is correct |
25 |
Correct |
108 ms |
24140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15448 KB |
Output is correct |
2 |
Correct |
16 ms |
15448 KB |
Output is correct |
3 |
Correct |
110 ms |
24360 KB |
Output is correct |
4 |
Correct |
126 ms |
24564 KB |
Output is correct |
5 |
Correct |
139 ms |
24608 KB |
Output is correct |
6 |
Incorrect |
159 ms |
25412 KB |
Output is incorrect: {s, t} is wrong. |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
15444 KB |
Output is correct |
2 |
Correct |
17 ms |
15448 KB |
Output is correct |
3 |
Correct |
123 ms |
24172 KB |
Output is correct |
4 |
Correct |
132 ms |
24440 KB |
Output is correct |
5 |
Incorrect |
113 ms |
24568 KB |
Output is incorrect: {s, t} is wrong. |
6 |
Halted |
0 ms |
0 KB |
- |