#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<"- "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y) {cerr<<x<<", ";}
#else
#define bug(...)
#endif // BALBIT
const int maxn=90005;
vector<int> ord;
int pe[maxn];
vector<pii> g[maxn];
ll toth;
void dfs(int v, int p) {
ord.pb(v);
for (pii e : g[v]) {
int u = e.f;
if (u != p) {
pe[u] = e.s;
dfs(u,v);
}
}
}
int n;
int lst(int rt) {
ord.clear();
memset(pe, -1, sizeof pe);
dfs(rt, -1);
int l = 1, r = n-1;
while (l!=r) {
int mid = (l+r)/2;
vector<int> tmp(n-1);
REP1(i,mid) {
tmp[pe[ord[i]]] = 1;
}
if (ask(tmp) < toth) {
// tot heavy
l = mid+1;
}else{
r = mid;
}
}
return ord[l];
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
n = N;
REP(i,N-1) {
g[U[i]].pb({V[i],i});
g[V[i]].pb({U[i],i});
}
vector<int> tmp(N-1,1);
toth=ask(tmp);
int S = lst(0);
int T = lst(S);
answer(S,T);
}
/*
5 4 1 2 2 1
0 1
1 2
1 3
0 4
*/
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:67:7: warning: unused variable 'M' [-Wunused-variable]
67 | int M = U.size();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2760 KB |
Output is correct |
2 |
Correct |
2 ms |
2760 KB |
Output is correct |
3 |
Correct |
2 ms |
2760 KB |
Output is correct |
4 |
Correct |
3 ms |
2700 KB |
Output is correct |
5 |
Correct |
2 ms |
2760 KB |
Output is correct |
6 |
Correct |
2 ms |
2760 KB |
Output is correct |
7 |
Correct |
2 ms |
2760 KB |
Output is correct |
8 |
Correct |
2 ms |
2760 KB |
Output is correct |
9 |
Correct |
2 ms |
2760 KB |
Output is correct |
10 |
Correct |
2 ms |
2760 KB |
Output is correct |
11 |
Correct |
2 ms |
2760 KB |
Output is correct |
12 |
Correct |
2 ms |
2760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2760 KB |
Output is correct |
2 |
Correct |
15 ms |
3400 KB |
Output is correct |
3 |
Correct |
179 ms |
8712 KB |
Output is correct |
4 |
Correct |
169 ms |
8712 KB |
Output is correct |
5 |
Correct |
185 ms |
8712 KB |
Output is correct |
6 |
Correct |
169 ms |
8616 KB |
Output is correct |
7 |
Correct |
168 ms |
8684 KB |
Output is correct |
8 |
Correct |
133 ms |
8620 KB |
Output is correct |
9 |
Correct |
162 ms |
8656 KB |
Output is correct |
10 |
Correct |
173 ms |
8668 KB |
Output is correct |
11 |
Correct |
174 ms |
9508 KB |
Output is correct |
12 |
Correct |
160 ms |
10232 KB |
Output is correct |
13 |
Correct |
155 ms |
9772 KB |
Output is correct |
14 |
Correct |
163 ms |
9660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3912 KB |
Output is correct |
2 |
Correct |
25 ms |
5108 KB |
Output is correct |
3 |
Correct |
37 ms |
6332 KB |
Output is correct |
4 |
Correct |
113 ms |
13904 KB |
Output is correct |
5 |
Correct |
106 ms |
13788 KB |
Output is correct |
6 |
Correct |
118 ms |
13752 KB |
Output is correct |
7 |
Correct |
105 ms |
13856 KB |
Output is correct |
8 |
Correct |
113 ms |
13732 KB |
Output is correct |
9 |
Correct |
115 ms |
13732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2760 KB |
Output is correct |
2 |
Correct |
16 ms |
3380 KB |
Output is correct |
3 |
Correct |
122 ms |
7468 KB |
Output is correct |
4 |
Correct |
152 ms |
8648 KB |
Output is correct |
5 |
Correct |
145 ms |
8696 KB |
Output is correct |
6 |
Correct |
171 ms |
8632 KB |
Output is correct |
7 |
Correct |
137 ms |
8708 KB |
Output is correct |
8 |
Correct |
165 ms |
8692 KB |
Output is correct |
9 |
Correct |
168 ms |
8716 KB |
Output is correct |
10 |
Correct |
148 ms |
8716 KB |
Output is correct |
11 |
Correct |
174 ms |
9168 KB |
Output is correct |
12 |
Correct |
166 ms |
10172 KB |
Output is correct |
13 |
Correct |
170 ms |
9760 KB |
Output is correct |
14 |
Correct |
167 ms |
10148 KB |
Output is correct |
15 |
Correct |
122 ms |
8712 KB |
Output is correct |
16 |
Correct |
127 ms |
8632 KB |
Output is correct |
17 |
Correct |
183 ms |
9836 KB |
Output is correct |
18 |
Correct |
166 ms |
9880 KB |
Output is correct |
19 |
Correct |
153 ms |
8992 KB |
Output is correct |
20 |
Correct |
160 ms |
10560 KB |
Output is correct |
21 |
Correct |
128 ms |
8916 KB |
Output is correct |
22 |
Correct |
144 ms |
9032 KB |
Output is correct |
23 |
Correct |
139 ms |
8820 KB |
Output is correct |
24 |
Correct |
158 ms |
9372 KB |
Output is correct |
25 |
Correct |
197 ms |
13156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
2888 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
2880 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |