#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), one(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);
for(int i=0;i<M;i++) if(one[i]==1) w[i]=1;
ll valb=ask(w);
if(valb>val0) e=mid;
else{
for(int i=s;i<=mid;i++) one[i]=1;
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]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 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 |
7 ms |
14424 KB |
Output is correct |
5 |
Correct |
6 ms |
14424 KB |
Output is correct |
6 |
Correct |
7 ms |
14424 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 |
7 ms |
14340 KB |
Output is correct |
11 |
Correct |
7 ms |
14424 KB |
Output is correct |
12 |
Correct |
8 ms |
14424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14424 KB |
Output is correct |
2 |
Correct |
17 ms |
15476 KB |
Output is correct |
3 |
Correct |
129 ms |
24116 KB |
Output is correct |
4 |
Correct |
110 ms |
24164 KB |
Output is correct |
5 |
Correct |
108 ms |
24184 KB |
Output is correct |
6 |
Correct |
106 ms |
24164 KB |
Output is correct |
7 |
Correct |
136 ms |
24172 KB |
Output is correct |
8 |
Correct |
119 ms |
24180 KB |
Output is correct |
9 |
Correct |
105 ms |
24172 KB |
Output is correct |
10 |
Correct |
116 ms |
24108 KB |
Output is correct |
11 |
Correct |
131 ms |
24116 KB |
Output is correct |
12 |
Correct |
133 ms |
24328 KB |
Output is correct |
13 |
Correct |
119 ms |
24072 KB |
Output is correct |
14 |
Correct |
124 ms |
24064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15448 KB |
Output is correct |
2 |
Correct |
22 ms |
16656 KB |
Output is correct |
3 |
Correct |
31 ms |
17556 KB |
Output is correct |
4 |
Correct |
83 ms |
24184 KB |
Output is correct |
5 |
Correct |
81 ms |
24204 KB |
Output is correct |
6 |
Correct |
82 ms |
23992 KB |
Output is correct |
7 |
Correct |
91 ms |
24096 KB |
Output is correct |
8 |
Correct |
90 ms |
24088 KB |
Output is correct |
9 |
Correct |
94 ms |
24104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14424 KB |
Output is correct |
2 |
Correct |
15 ms |
15448 KB |
Output is correct |
3 |
Correct |
86 ms |
22048 KB |
Output is correct |
4 |
Correct |
108 ms |
24172 KB |
Output is correct |
5 |
Correct |
105 ms |
24248 KB |
Output is correct |
6 |
Correct |
106 ms |
24172 KB |
Output is correct |
7 |
Correct |
120 ms |
24172 KB |
Output is correct |
8 |
Correct |
107 ms |
24168 KB |
Output is correct |
9 |
Correct |
123 ms |
24340 KB |
Output is correct |
10 |
Correct |
110 ms |
24308 KB |
Output is correct |
11 |
Correct |
116 ms |
24100 KB |
Output is correct |
12 |
Correct |
111 ms |
24076 KB |
Output is correct |
13 |
Correct |
136 ms |
24112 KB |
Output is correct |
14 |
Correct |
114 ms |
24084 KB |
Output is correct |
15 |
Correct |
120 ms |
24156 KB |
Output is correct |
16 |
Correct |
104 ms |
24164 KB |
Output is correct |
17 |
Correct |
121 ms |
24072 KB |
Output is correct |
18 |
Correct |
112 ms |
24056 KB |
Output is correct |
19 |
Correct |
106 ms |
24176 KB |
Output is correct |
20 |
Correct |
124 ms |
24072 KB |
Output is correct |
21 |
Correct |
117 ms |
24424 KB |
Output is correct |
22 |
Correct |
98 ms |
24436 KB |
Output is correct |
23 |
Correct |
107 ms |
24592 KB |
Output is correct |
24 |
Correct |
102 ms |
24480 KB |
Output is correct |
25 |
Correct |
107 ms |
24144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
15448 KB |
Output is correct |
2 |
Correct |
18 ms |
15520 KB |
Output is correct |
3 |
Correct |
116 ms |
24368 KB |
Output is correct |
4 |
Correct |
167 ms |
24608 KB |
Output is correct |
5 |
Correct |
162 ms |
25040 KB |
Output is correct |
6 |
Correct |
164 ms |
25008 KB |
Output is correct |
7 |
Correct |
164 ms |
24752 KB |
Output is correct |
8 |
Incorrect |
158 ms |
24752 KB |
Output is incorrect: {s, t} is wrong. |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
15448 KB |
Output is correct |
2 |
Correct |
23 ms |
15448 KB |
Output is correct |
3 |
Correct |
125 ms |
24116 KB |
Output is correct |
4 |
Correct |
137 ms |
24204 KB |
Output is correct |
5 |
Correct |
137 ms |
24352 KB |
Output is correct |
6 |
Correct |
153 ms |
24744 KB |
Output is correct |
7 |
Correct |
119 ms |
24624 KB |
Output is correct |
8 |
Correct |
125 ms |
24540 KB |
Output is correct |
9 |
Incorrect |
144 ms |
24196 KB |
Output is incorrect: {s, t} is wrong. |
10 |
Halted |
0 ms |
0 KB |
- |