#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "highway.h"
int n, m;
VVPI gp;
VI depth;
VI parind;
VI par;
VI euler;
void dfs(int u = 0, int p = -1, int pind = -1) {
if (u) euler.pb(u);
parind[u] = pind;
par[u] = p;
for (auto[v, ind] : gp[u]) if (ind != pind) {
depth[v] = depth[u]+1;
dfs(v, u, ind);
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
n = N;
m = U.size();
gp = VVPI(n);
rep(i, m) {
gp[U[i]].pb({V[i], i});
gp[V[i]].pb({U[i], i});
}
depth = parind = par = VI(n);
euler = VI();
dfs();
ll base = ask(VI(m));
int d = base/A;
int s;
if (true) {
/*searching for value of s*/
auto f = [&](int x) {
VI W(m);
replr(i, 0, x) W[parind[euler[i]]] = true;
return (ask(W)-base)/(B-A);
};
int l = -1, r = m-1;
while (l+1 < r) {
int m = (l + r) / 2;
if (f(m) < d) l = m;
else r = m;
}
s = euler[r];
}
/*cout << "FIRST NODE: " << s << endl;*/
depth = parind = par = VI(n);
euler = VI();
dfs(s);
int t;
if (true) {
/*searching for value of t*/
VI b;
rep(u, n) if (depth[u] == d) b.pb(u);
auto f = [&](int x) {
VI W(m);
replr(i, 0, x) W[parind[b[i]]] = true;
return ask(W) > base;
};
int l = -1, r = b.size()-1;
while (l + 1 < r) {
int m = (l + r) / 2;
if (f(m)) r = m;
else l = m;
}
t = b[r];
}
/*cout << "SECOND NODE: " << t << endl;*/
answer(s, t);
}
/*ask(VI w);*/
/*answer(int s, int t)*/
Compilation message
highway.cpp: In function 'void dfs(int, int, int)':
highway.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | for (auto[v, ind] : gp[u]) if (ind != pind) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
404 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
1276 KB |
Output is correct |
3 |
Correct |
69 ms |
9308 KB |
Output is correct |
4 |
Correct |
72 ms |
9740 KB |
Output is correct |
5 |
Correct |
72 ms |
9212 KB |
Output is correct |
6 |
Correct |
72 ms |
9196 KB |
Output is correct |
7 |
Correct |
71 ms |
9728 KB |
Output is correct |
8 |
Correct |
75 ms |
9244 KB |
Output is correct |
9 |
Correct |
69 ms |
9224 KB |
Output is correct |
10 |
Correct |
74 ms |
9260 KB |
Output is correct |
11 |
Correct |
67 ms |
9564 KB |
Output is correct |
12 |
Correct |
74 ms |
10140 KB |
Output is correct |
13 |
Correct |
70 ms |
9700 KB |
Output is correct |
14 |
Correct |
80 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1624 KB |
Output is correct |
2 |
Correct |
11 ms |
3160 KB |
Output is correct |
3 |
Correct |
20 ms |
4584 KB |
Output is correct |
4 |
Correct |
62 ms |
12912 KB |
Output is correct |
5 |
Correct |
59 ms |
12900 KB |
Output is correct |
6 |
Correct |
61 ms |
12764 KB |
Output is correct |
7 |
Correct |
58 ms |
12816 KB |
Output is correct |
8 |
Correct |
67 ms |
12792 KB |
Output is correct |
9 |
Correct |
60 ms |
12764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
1448 KB |
Output is correct |
3 |
Correct |
66 ms |
7416 KB |
Output is correct |
4 |
Correct |
78 ms |
9204 KB |
Output is correct |
5 |
Correct |
69 ms |
9416 KB |
Output is correct |
6 |
Correct |
69 ms |
9200 KB |
Output is correct |
7 |
Correct |
72 ms |
9180 KB |
Output is correct |
8 |
Correct |
85 ms |
9160 KB |
Output is correct |
9 |
Correct |
74 ms |
9252 KB |
Output is correct |
10 |
Correct |
75 ms |
9244 KB |
Output is correct |
11 |
Correct |
91 ms |
9228 KB |
Output is correct |
12 |
Correct |
84 ms |
10184 KB |
Output is correct |
13 |
Correct |
91 ms |
9848 KB |
Output is correct |
14 |
Correct |
79 ms |
10096 KB |
Output is correct |
15 |
Correct |
68 ms |
9252 KB |
Output is correct |
16 |
Correct |
64 ms |
9188 KB |
Output is correct |
17 |
Correct |
82 ms |
9932 KB |
Output is correct |
18 |
Correct |
76 ms |
9928 KB |
Output is correct |
19 |
Correct |
69 ms |
9180 KB |
Output is correct |
20 |
Correct |
75 ms |
10528 KB |
Output is correct |
21 |
Correct |
62 ms |
10252 KB |
Output is correct |
22 |
Correct |
72 ms |
9868 KB |
Output is correct |
23 |
Correct |
76 ms |
9788 KB |
Output is correct |
24 |
Correct |
85 ms |
10108 KB |
Output is correct |
25 |
Correct |
98 ms |
12544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
286 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
251 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |