#ifdef LOCAL
#else
#include "highway.h"
#endif
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int inf = 2e09; ll infll = 2e18;
#ifdef LOCAL
ll ask(vector<int> w){ return 0; }
#else
#endif
ll main_dist;
struct st{
int sz, u, i;
st(){}
st(int S, int U, int I) : sz(S), u(U), i(I) {}
bool operator<(const st &x) const{ return sz > x.sz; }
};
struct cent{
int l = 0;
vector<int> vis, sz, d_src, w; vector<vector<pii>> g;
void init(int n, vector<vector<pii>> &G){
vis = vector<int>(), vis.resize(n);
sz = vector<int>(), sz.resize(n);
d_src = vector<int>(), d_src.resize(n);
w.resize(n-1, 0);
g = G;
}
void dfs(int x){
vis[x] = l, sz[x] = 1;
for(pii u : g[x]) if(vis[u.fi] < l) dfs(u.fi), sz[x] += sz[u.fi];
}
int find_cent(int x, int n){
vis[x] = l; int ret = x;
for(pii u : g[x]) if(vis[u.fi] < l && n/2 < sz[u.fi]) ret = find_cent(u.fi, n);
return ret;
}
vector<st> tmp; //fi to rozmiar, se = indeks
int deco(int x){
tmp = vector<st>();
++l; dfs(x);
++l; int cnt = find_cent(x, sz[x]);
++l; dfs(cnt);
vis[cnt] = inf;
int ret = cnt;
bool not_here = 0;
for(pii u : g[cnt]) if(vis[u.fi] != inf){
if(d_src[u.fi] < d_src[cnt]){
w[u.se] = 1;
if(main_dist == ask(w)) w[u.se] = 0, ret = deco(u.fi), not_here = 1;
w[u.se] = 0;
}
else tmp.emplace_back(sz[u.fi], u.fi, u.se);
}
if(!not_here){
sort(tmp.begin(), tmp.end());
for(st u : tmp){
w[u.i] = 1;
if(main_dist < ask(w)){ w[u.i] = 0, ret = deco(u.u); break; }
w[u.i] = 0;
}
}
tmp = vector<st>();
return ret;
}
void dfs_dist(int x, int dist){
vis[x] = l, d_src[x] = dist;
for(pii u : g[x]) if(vis[u.fi] < l) dfs_dist(u.fi, dist+1);
}
int start(int x){
++l; dfs_dist(x, 0);
return deco(x);
}
} cent;
void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
vector<vector<pii>> g(n);
int m = ssize(U);
for(int i = 0; i < m; ++i) g[U[i]].emplace_back(V[i], i), g[V[i]].emplace_back(U[i], i);
vector<int> w(m, 0);
main_dist = ask(w);
int l = 0, r = m-1, mid;
while(l != r){
mid = (l+r)>>1;
for(int i = l; i <= mid; ++i) w[i] = 1;
if(ask(w) != main_dist) r = mid;
else l = mid+1;
fill(w.begin(), w.end(), 0);
}
//znajdujemy s
cent.init(n, g);
cent.vis[V[l]] = inf;
int s = cent.start(U[l]);
cent.init(n, g);
cent.vis[U[l]] = inf;
int e = cent.start(V[l]);
if(s > e) swap(s, e);
#ifdef LOCAL
#else
answer(s, e);
#endif
}
#ifdef LOCAL
int main(){
int T = 1;
for(++T; --T; ) ;//find_pair();
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
440 KB |
Output is correct |
2 |
Correct |
0 ms |
444 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
0 ms |
440 KB |
Output is correct |
7 |
Correct |
0 ms |
696 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Correct |
0 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
444 KB |
Output is correct |
12 |
Correct |
0 ms |
448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
520 KB |
Output is correct |
2 |
Correct |
9 ms |
2164 KB |
Output is correct |
3 |
Correct |
90 ms |
14256 KB |
Output is correct |
4 |
Correct |
94 ms |
14264 KB |
Output is correct |
5 |
Correct |
103 ms |
14248 KB |
Output is correct |
6 |
Correct |
93 ms |
14256 KB |
Output is correct |
7 |
Correct |
93 ms |
14256 KB |
Output is correct |
8 |
Correct |
137 ms |
14252 KB |
Output is correct |
9 |
Correct |
97 ms |
14260 KB |
Output is correct |
10 |
Correct |
118 ms |
14268 KB |
Output is correct |
11 |
Correct |
111 ms |
14076 KB |
Output is correct |
12 |
Correct |
109 ms |
14480 KB |
Output is correct |
13 |
Correct |
95 ms |
14480 KB |
Output is correct |
14 |
Correct |
121 ms |
14284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2292 KB |
Output is correct |
2 |
Correct |
17 ms |
3908 KB |
Output is correct |
3 |
Correct |
28 ms |
5684 KB |
Output is correct |
4 |
Correct |
81 ms |
15388 KB |
Output is correct |
5 |
Correct |
104 ms |
15432 KB |
Output is correct |
6 |
Correct |
79 ms |
16044 KB |
Output is correct |
7 |
Correct |
71 ms |
16592 KB |
Output is correct |
8 |
Correct |
73 ms |
15672 KB |
Output is correct |
9 |
Correct |
71 ms |
15820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
1992 KB |
Output is correct |
3 |
Correct |
61 ms |
11448 KB |
Output is correct |
4 |
Correct |
106 ms |
14476 KB |
Output is correct |
5 |
Correct |
92 ms |
14296 KB |
Output is correct |
6 |
Correct |
84 ms |
14252 KB |
Output is correct |
7 |
Correct |
93 ms |
14256 KB |
Output is correct |
8 |
Correct |
91 ms |
14452 KB |
Output is correct |
9 |
Correct |
93 ms |
14252 KB |
Output is correct |
10 |
Correct |
102 ms |
14332 KB |
Output is correct |
11 |
Correct |
108 ms |
14104 KB |
Output is correct |
12 |
Correct |
105 ms |
14484 KB |
Output is correct |
13 |
Correct |
108 ms |
14344 KB |
Output is correct |
14 |
Incorrect |
101 ms |
14292 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
2148 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
2148 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |