This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
vector<pii> adj[maxn];
ll mind;
vector<int> tmp;
int ord[maxn];
void dfs(int n, int par, int &cur, int lim) {
ord[cur++] = n;
if (cur > lim) return;
for (auto [v, id]:adj[n]) {
if (v != par && cur + 1 <= lim) {
tmp[id] = 0;
dfs(v, n, cur, lim);
if (cur > lim) return;
}
}
}
int getind(int n, int root) {
int low = 0, up = n;
tmp.resize(n - 1, 0);
dfs(root, 0,low, 1<<30);
low = 0;
while (low < up - 1) {
int mid = (low + up) / 2;
for (int i = 0;i < n - 1;i++) tmp[i] = 1;
int ini = 0;
dfs(root, 0, ini, mid);
//debug(low, mid, up);
//pary(tmp.begin(), tmp.end());
ll val = ask(tmp);
if (val == mind) {
up = mid;
} else {
low = mid;
}
}
//debug(up, ord[up-1]);
return ord[up-1];
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
vector<int> ini(M, 0);
mind = ask(ini);
for (int i = 0;i < M;i++) {
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
int s = getind(N, 0);
int t = getind(N, s);
debug(s, t);
answer(s, t);
}
/*
4 3 5 8 1 3
0 1
0 2
1 3
*/
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:13:20: warning: statement has no effect [-Wunused-value]
13 | #define debug(...) 0
| ^
highway.cpp:71:2: note: in expansion of macro 'debug'
71 | debug(s, t);
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |