#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(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 = 9e4+5;
int n,m;
vector<PII> v[MAXN];
vector<int32_t> w, tour;
vector<Edge> e;
int d[MAXN], ans;
void dfs(int s, int pa) {
FORX(u,v[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);
}
}
int find_end(int s, int pa) {
tour.clear();
dfs(s,pa);
// FORX(u,tour) cout << u << " ";
// cout << ln;
int l = -1, r = tour.size()-1;
while (l < r) {
FOR(i,0,m) w[i] = 0;
int mid = (l+r+1)/2;
FOR(i,mid,r+1) w[tour[i]] = 1;
int val = ask(w);
if (val == ans) r = mid-1;
else l = mid;
}
// cout << "s l: " << s << " " << l << ln;
return (l == -1 ? s : e[tour[l]].y);
}
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});
}
dfs(0,-1);
FOR(i,0,m) w.PB(0);
ans = ask(w);
// find intermediate edge
int l = 0, r = m-1;
while (l < r) {
FOR(i,0,n) w[i] = 0;
int mid = (l+r+1)/2;
FOR(i,mid,r+1) w[tour[i]] = 1;
int val = ask(w);
// cout << "m a: " << mid << " " << val << ln;
if (val == ans) r = mid-1;
else l = mid;
}
int xs = e[tour[l]].x, ys = e[tour[l]].y;
// cout << "xs ys: " << xs << " " << ys << ln;
int32_t S = ys, T = find_end(xs,ys);
// cout << "S T: " << S << " " << T << ln;
answer(S,T);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2416 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
2 ms |
2384 KB |
Output is correct |
12 |
Correct |
2 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2512 KB |
Output is correct |
2 |
Correct |
12 ms |
3448 KB |
Output is correct |
3 |
Correct |
78 ms |
11812 KB |
Output is correct |
4 |
Correct |
87 ms |
11800 KB |
Output is correct |
5 |
Correct |
90 ms |
11800 KB |
Output is correct |
6 |
Correct |
75 ms |
11796 KB |
Output is correct |
7 |
Correct |
113 ms |
11792 KB |
Output is correct |
8 |
Correct |
112 ms |
11800 KB |
Output is correct |
9 |
Correct |
102 ms |
11788 KB |
Output is correct |
10 |
Correct |
87 ms |
11792 KB |
Output is correct |
11 |
Correct |
98 ms |
13624 KB |
Output is correct |
12 |
Correct |
97 ms |
14592 KB |
Output is correct |
13 |
Correct |
103 ms |
13776 KB |
Output is correct |
14 |
Correct |
86 ms |
13888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
4212 KB |
Output is correct |
2 |
Correct |
21 ms |
5932 KB |
Output is correct |
3 |
Correct |
30 ms |
7728 KB |
Output is correct |
4 |
Correct |
80 ms |
18436 KB |
Output is correct |
5 |
Correct |
68 ms |
18460 KB |
Output is correct |
6 |
Correct |
88 ms |
18424 KB |
Output is correct |
7 |
Correct |
60 ms |
18436 KB |
Output is correct |
8 |
Correct |
84 ms |
18400 KB |
Output is correct |
9 |
Correct |
88 ms |
18368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2512 KB |
Output is correct |
2 |
Correct |
8 ms |
3468 KB |
Output is correct |
3 |
Correct |
61 ms |
9996 KB |
Output is correct |
4 |
Correct |
92 ms |
11792 KB |
Output is correct |
5 |
Correct |
74 ms |
11788 KB |
Output is correct |
6 |
Correct |
92 ms |
11832 KB |
Output is correct |
7 |
Correct |
85 ms |
11796 KB |
Output is correct |
8 |
Correct |
74 ms |
11784 KB |
Output is correct |
9 |
Correct |
103 ms |
11796 KB |
Output is correct |
10 |
Correct |
93 ms |
11804 KB |
Output is correct |
11 |
Correct |
80 ms |
13148 KB |
Output is correct |
12 |
Correct |
108 ms |
14556 KB |
Output is correct |
13 |
Correct |
110 ms |
13944 KB |
Output is correct |
14 |
Correct |
124 ms |
14508 KB |
Output is correct |
15 |
Correct |
121 ms |
11800 KB |
Output is correct |
16 |
Correct |
117 ms |
11796 KB |
Output is correct |
17 |
Correct |
95 ms |
14052 KB |
Output is correct |
18 |
Correct |
125 ms |
14184 KB |
Output is correct |
19 |
Correct |
102 ms |
11804 KB |
Output is correct |
20 |
Correct |
85 ms |
14968 KB |
Output is correct |
21 |
Correct |
64 ms |
11388 KB |
Output is correct |
22 |
Correct |
67 ms |
11392 KB |
Output is correct |
23 |
Correct |
65 ms |
11484 KB |
Output is correct |
24 |
Correct |
87 ms |
12424 KB |
Output is correct |
25 |
Correct |
114 ms |
18128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
161 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
153 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |