#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int64_t(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
#define int long long
struct Edge {
int x,y,depth;
};
const int MAXN = 1.3e5+5;
int n,m;
vector<PII> v[MAXN], tour;
vector<int32_t> w;
vector<Edge> e;
int dist[2][MAXN], eist[2][MAXN], ans;
bool intree[MAXN];
// void dfs(int s, int pa, vector<PII> vec[]) {
// FORX(u,vec[s]) {
// if (u.F == pa) continue;
// if (e[u.S].y != u.F) swap(e[u.S].x, e[u.S].y);
// tour.PB(u.S);
// dfs(u.F,s,vec);
// }
// }
void pre_bfs(int start, int idx) {
FOR(i,0,n) dist[idx][i] = INF;
dist[idx][start] = 0;
queue<int> q;
q.push(start);
vector<bool> z(n,0);
while (!q.empty()) {
int s = q.front();
q.pop();
if (z[s]) continue;
z[s] = 1;
FORX(u,v[s]) {
if (dist[idx][s]+1 < dist[idx][u.F]) {
dist[idx][u.F] = dist[idx][s]+1;
// eist[idx][u.S] = dist[idx][u.F];
q.push(u.F);
}
}
}
}
int find_edge() {
int l = 0, r = m-1;
while (l < r) {
FOR(i,0,m) w[i] = 0;
int mid = (l+r+1)/2;
FOR(i,mid,m) w[i] = 1;
int val = ask(w);
if (val == ans) r = mid-1;
else l = mid;
}
return l;
}
int find_edge1(int orig) {
// tour.clear();
// dfs(s,pa,vec);
// FORX(u,tour) cout << u.S << " ";
// cout << ln;
// FOR(i,0,m) cout << intree[i] << " ";
// cout << ln;
// && max(e[tour[i].S].x,e[tour[i].S].y) == 12
int flowey = tour.size();
int l = -1, r = flowey-1;
// FOR(i,0,(tour.size())) {
// if (min(e[tour[i].S].x,e[tour[i].S].y) == 10) {
// cout << "NYAHAAH " << i << " " << e[tour[i].S].x << " " << e[tour[i].S].y << ln;
// }
// }
// cout << "intree4 " << intree[1] << ln;
while (l < r) {
// FOR(i,0,m) w[i] = !intree[i];
FOR(i,0,m) w[i] = !intree[i];
int mid = (l+r+1)/2;
FOR(i,mid,flowey) w[tour[i].S] = 1;
w[orig] = 0;
// cout << "l r: " << l << " " << mid << " " << r << ln;
// cout << "w[1]: " << w[1] << ln;
int val = ask(w);
// cout << val;
if (val == ans) r = mid-1;
else {
// if (mid == 13 && r == 13) cout << "NYEHEHEHE " << e[tour[11].S].x << " " << e[tour[11].S].y << ln;
l = mid;
}
}
// cout << "s l tour[l]: " << s << " " << l << " " << tour[l].S << ln;
return l == -1 ? -1 : tour[l].S;
}
void bfs(int start, int idx) {
FOR(i,0,m) intree[i] = 1;
tour.clear();
queue<int> q;
q.push(start);
vector<int> d(n,INF);
vector<PII> p(n,{-1,-1});
vector<bool> z(n,0);
d[start] = 0LL;
while (!q.empty()) {
int s = q.front();
q.pop();
if (z[s]) continue;
z[s] = 1;
// cout << s << " ";
FORX(u,v[s]) {
if (dist[idx][u.F] < dist[idx^1][u.F]) {
if (d[s]+1 < d[u.F]) {
d[u.F] = d[s]+1;
if (e[u.S].y != u.F) swap(e[u.S].x, e[u.S].y);
if (dist[idx][u.F] < dist[idx^1][u.F]) tour.PB({d[u.F],u.S});
q.push(u.F);
}
else if (d[s]+1 == d[u.F]) intree[u.S] = 0;
}
else intree[u.S] = 0;
}
}
sort(ALL(tour));
// FOR(i,0,n) cout << p[i].F << " ";
// cout << ln;
// cout << ln;
// FOR(i,0,n) {
// if (p[i].F != -1) {
// vec1[p[i].F].PB({i,p[i].S});
// vec1[i].PB(p[i]);
// intree[p[i].S] = 1;
// }
// }
}
void find_pair(int32_t N, std::vector<int32_t> U, std::vector<int32_t> V, int32_t A, int32_t B) {
n = N; m = U.size();
FOR(i,0,m) {
v[U[i]].PB({V[i],i});
v[V[i]].PB({U[i],i});
e.PB({U[i],V[i],-1LL});
}
// bfs(0,-1,v,v1);
// FOR(i,0,m) cout << intree[i] << " ";
// cout << ln;
FOR(i,0,m) w.PB(0);
ans = ask(w);
// cout << ans << ln;
int edge = find_edge();
// cout << "x y: " << e[edge].x << " " << e[edge].y << ln;
int xs = e[edge].x, ys = e[edge].y;
pre_bfs(xs,0);
pre_bfs(ys,1);
// cout << "xs ys: " << xs << " " << ys << ln;
// FOR(i,0,n) {
// cout << i << ": ";
// FORX(u,v2[i]) cout << u.F << " ";
// cout << ln;
// }
// return;
bfs(xs,0);
int edge1 = find_edge1(edge);
int s = edge1 == -1 ? xs : e[edge1].y;
// cout << xs << ln;
// if (s == xs) while (true) int bruh = 0;
bfs(ys,1);
int edge2 = find_edge1(edge);
int t = edge2 == -1 ? ys : e[edge2].y;
// cout << "S T: " << s << " " << t << ln;
FOR(i,0,m) w[i] = 0;
answer(s,t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3280 KB |
Output is correct |
2 |
Correct |
2 ms |
3392 KB |
Output is correct |
3 |
Correct |
2 ms |
3280 KB |
Output is correct |
4 |
Correct |
2 ms |
3280 KB |
Output is correct |
5 |
Correct |
2 ms |
3280 KB |
Output is correct |
6 |
Correct |
2 ms |
3292 KB |
Output is correct |
7 |
Correct |
2 ms |
3280 KB |
Output is correct |
8 |
Correct |
2 ms |
3280 KB |
Output is correct |
9 |
Correct |
2 ms |
3376 KB |
Output is correct |
10 |
Correct |
2 ms |
3380 KB |
Output is correct |
11 |
Correct |
2 ms |
3280 KB |
Output is correct |
12 |
Correct |
2 ms |
3376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3536 KB |
Output is correct |
2 |
Correct |
12 ms |
5156 KB |
Output is correct |
3 |
Correct |
127 ms |
19172 KB |
Output is correct |
4 |
Correct |
122 ms |
19124 KB |
Output is correct |
5 |
Correct |
113 ms |
19236 KB |
Output is correct |
6 |
Correct |
113 ms |
19176 KB |
Output is correct |
7 |
Correct |
133 ms |
19168 KB |
Output is correct |
8 |
Correct |
117 ms |
19172 KB |
Output is correct |
9 |
Correct |
147 ms |
18912 KB |
Output is correct |
10 |
Correct |
106 ms |
19212 KB |
Output is correct |
11 |
Correct |
104 ms |
17840 KB |
Output is correct |
12 |
Correct |
137 ms |
18884 KB |
Output is correct |
13 |
Correct |
125 ms |
19148 KB |
Output is correct |
14 |
Correct |
125 ms |
19204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5004 KB |
Output is correct |
2 |
Correct |
19 ms |
6452 KB |
Output is correct |
3 |
Correct |
37 ms |
8244 KB |
Output is correct |
4 |
Correct |
66 ms |
17188 KB |
Output is correct |
5 |
Correct |
85 ms |
17272 KB |
Output is correct |
6 |
Correct |
93 ms |
18496 KB |
Output is correct |
7 |
Correct |
70 ms |
18640 KB |
Output is correct |
8 |
Correct |
93 ms |
17312 KB |
Output is correct |
9 |
Correct |
112 ms |
18392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3544 KB |
Output is correct |
2 |
Correct |
10 ms |
5132 KB |
Output is correct |
3 |
Correct |
75 ms |
16232 KB |
Output is correct |
4 |
Correct |
112 ms |
19148 KB |
Output is correct |
5 |
Correct |
102 ms |
19184 KB |
Output is correct |
6 |
Correct |
127 ms |
19192 KB |
Output is correct |
7 |
Correct |
106 ms |
19204 KB |
Output is correct |
8 |
Correct |
99 ms |
19196 KB |
Output is correct |
9 |
Correct |
115 ms |
17712 KB |
Output is correct |
10 |
Correct |
143 ms |
19188 KB |
Output is correct |
11 |
Correct |
127 ms |
19156 KB |
Output is correct |
12 |
Correct |
122 ms |
18928 KB |
Output is correct |
13 |
Correct |
135 ms |
17900 KB |
Output is correct |
14 |
Correct |
124 ms |
17844 KB |
Output is correct |
15 |
Correct |
116 ms |
19116 KB |
Output is correct |
16 |
Correct |
110 ms |
19120 KB |
Output is correct |
17 |
Correct |
133 ms |
19196 KB |
Output is correct |
18 |
Correct |
133 ms |
19180 KB |
Output is correct |
19 |
Correct |
109 ms |
19216 KB |
Output is correct |
20 |
Correct |
113 ms |
19112 KB |
Output is correct |
21 |
Correct |
91 ms |
18728 KB |
Output is correct |
22 |
Correct |
76 ms |
18720 KB |
Output is correct |
23 |
Correct |
106 ms |
17112 KB |
Output is correct |
24 |
Correct |
81 ms |
17108 KB |
Output is correct |
25 |
Correct |
117 ms |
19132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4984 KB |
Output is correct |
2 |
Correct |
16 ms |
5348 KB |
Output is correct |
3 |
Correct |
146 ms |
18500 KB |
Output is correct |
4 |
Correct |
143 ms |
21076 KB |
Output is correct |
5 |
Correct |
187 ms |
21460 KB |
Output is correct |
6 |
Correct |
166 ms |
22992 KB |
Output is correct |
7 |
Correct |
196 ms |
21432 KB |
Output is correct |
8 |
Correct |
160 ms |
21336 KB |
Output is correct |
9 |
Correct |
133 ms |
16524 KB |
Output is correct |
10 |
Correct |
157 ms |
17408 KB |
Output is correct |
11 |
Correct |
119 ms |
19044 KB |
Output is correct |
12 |
Correct |
181 ms |
19804 KB |
Output is correct |
13 |
Correct |
163 ms |
21072 KB |
Output is correct |
14 |
Correct |
163 ms |
21620 KB |
Output is correct |
15 |
Correct |
181 ms |
21704 KB |
Output is correct |
16 |
Correct |
137 ms |
18260 KB |
Output is correct |
17 |
Correct |
87 ms |
18872 KB |
Output is correct |
18 |
Correct |
86 ms |
19264 KB |
Output is correct |
19 |
Correct |
90 ms |
19032 KB |
Output is correct |
20 |
Correct |
110 ms |
19132 KB |
Output is correct |
21 |
Correct |
169 ms |
23000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
5024 KB |
Output is correct |
2 |
Correct |
13 ms |
5260 KB |
Output is correct |
3 |
Correct |
128 ms |
20260 KB |
Output is correct |
4 |
Correct |
145 ms |
19136 KB |
Output is correct |
5 |
Correct |
159 ms |
20716 KB |
Output is correct |
6 |
Correct |
179 ms |
22676 KB |
Output is correct |
7 |
Correct |
153 ms |
18780 KB |
Output is correct |
8 |
Correct |
131 ms |
18848 KB |
Output is correct |
9 |
Correct |
155 ms |
21112 KB |
Output is correct |
10 |
Correct |
171 ms |
21632 KB |
Output is correct |
11 |
Correct |
184 ms |
21388 KB |
Output is correct |
12 |
Correct |
181 ms |
22648 KB |
Output is correct |
13 |
Correct |
122 ms |
19056 KB |
Output is correct |
14 |
Correct |
128 ms |
17284 KB |
Output is correct |
15 |
Correct |
154 ms |
19120 KB |
Output is correct |
16 |
Correct |
150 ms |
17392 KB |
Output is correct |
17 |
Correct |
121 ms |
18780 KB |
Output is correct |
18 |
Correct |
167 ms |
17272 KB |
Output is correct |
19 |
Correct |
161 ms |
19896 KB |
Output is correct |
20 |
Correct |
216 ms |
20932 KB |
Output is correct |
21 |
Correct |
202 ms |
21552 KB |
Output is correct |
22 |
Correct |
156 ms |
21380 KB |
Output is correct |
23 |
Correct |
197 ms |
21224 KB |
Output is correct |
24 |
Correct |
191 ms |
22756 KB |
Output is correct |
25 |
Correct |
187 ms |
21644 KB |
Output is correct |
26 |
Correct |
196 ms |
21672 KB |
Output is correct |
27 |
Correct |
103 ms |
19128 KB |
Output is correct |
28 |
Correct |
136 ms |
18956 KB |
Output is correct |
29 |
Correct |
102 ms |
19264 KB |
Output is correct |
30 |
Correct |
101 ms |
19140 KB |
Output is correct |
31 |
Correct |
91 ms |
19068 KB |
Output is correct |
32 |
Correct |
123 ms |
18844 KB |
Output is correct |
33 |
Correct |
111 ms |
19132 KB |
Output is correct |
34 |
Correct |
91 ms |
19152 KB |
Output is correct |
35 |
Correct |
85 ms |
19196 KB |
Output is correct |
36 |
Correct |
87 ms |
18796 KB |
Output is correct |
37 |
Correct |
85 ms |
19328 KB |
Output is correct |
38 |
Correct |
104 ms |
19296 KB |
Output is correct |
39 |
Correct |
140 ms |
22956 KB |
Output is correct |
40 |
Correct |
173 ms |
22872 KB |
Output is correct |
41 |
Correct |
154 ms |
22936 KB |
Output is correct |
42 |
Correct |
147 ms |
21592 KB |
Output is correct |