# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059936 | Alihan_8 | Island Hopping (JOI24_island) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
using namespace std;
//--------------------------------------------------------------------//
// Don't change this part of the code!!!
#ifdef ONLINE_JUDGE
int query(int v, int k) {
cout << "que " << v << " " << k << endl;
fflush(stdout);
int x;
cin >> x;
return x;
}
void answer(int x, int y) {
cout << "ans " << x << " " << y << endl;
fflush(stdout);
}
#else
#include "grader.cpp"
int query(int v, int k) {
return Query(v, k);
}
void answer(int x, int y) {
Answer(x, y);
}
#endif
//--------------------------------------------------------------------//
#define pb push_back
#define all(x) x.begin(), x.end()
#define ln '\n'
void solve(int n, int _L){
vector <int> p, q(n + 1);
for ( int i = 0; i + 1 < n; i++ ){
int x = query(1, i + 1);
p.pb(x); q[x] = i;
}
vector <int> fa(n + 1);
reverse(all(p));
for ( auto &u: p ){
if ( fa[u] ) continue;
int v = -1, k = 0;
while ( q[v = query(u, ++k)] > q[u] ){
fa[v] = u;
}
fa[u] = v;
}
for ( int i = 2; i <= n; i++ ){
answer(i, fa[i]);
}
}
//--------------------------------------------------------------------//
// Don't change this part of the code!!!
#ifdef ONLINE_JUDGE
int main() {
int N, L;
cin >> N >> L;
solve(N, L);
cout << "finish 1 1" << endl;
fflush(stdout);
return 0;
}
#endif
//--------------------------------------------------------------------//
/*
4 16
1 2
2 4
4 3
*/