이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int n = N, M = U.size();
vector <vector<ar<int,2>>> adj(n);
for ( int i = 0; i < M; i++ ){
adj[U[i]].pb({V[i], i});
adj[V[i]].pb({U[i], i});
}
vector <int> w(M);
i64 C = ask(w);
int l = 0, r = n - 1, ans;
while ( l <= r ){
int m = (l + r) / 2;
if ( r - l > 60000 ) m = 60000;
w.assign(M, 0);
for ( int u = m + 1; u < n; u++ ){
for ( auto &[v, j]: adj[u] ){
w[j] = 1;
}
}
if ( ask(w) == C ){
ans = m;
r = m - 1;
} else l = m + 1;
}
int root = ans;
vector <int> fa(n), ls, us(n);
queue <int> q;
q.push(root); us[root] = 1;
while ( !q.empty() ){
int u = q.front();
q.pop();
ls.pb(u);
for ( auto &[v, j]: adj[u] ){
if ( us[v] ) continue;
us[v] = 1;
fa[v] = u;
q.push(v);
}
}
vector <int> e(n, -1);
for ( int u = 0; u < n; u++ ){
for ( auto &[v, j]: adj[u] ){
if ( fa[u] == v ){
e[u] = j;
}
}
}
l = 1, r = n - 1;
while ( l <= r ){
int m = (l + r) / 2;
if ( r - l > 60000 ) m = 60000;
w.assign(M, 1);
for ( int i = 1; i <= m; i++ ){
w[e[ls[i]]] = 0;
}
if ( ask(w) == C ){
ans = m;
r = m - 1;
} else l = m + 1;
}
int sx = ls[ans];
vector <int> pth;
{ // path from sx to root
int it = sx;
while ( it != root ){
pth.pb(e[it]);
it = fa[it];
}
}
l = 0, r = n - 1;
while ( l <= r ){
int m = (l + r) / 2;
w.assign(M, 1);
for ( auto &j: pth ) w[j] = 0;
for ( int i = 0; i < m; i++ ){
w[e[ls[i + 1]]] = 0;
}
if ( ask(w) == C ){
ans = m;
r = m - 1;
} else l = m + 1;
}
int se = ls[l];
answer(sx, se);
}
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:127:14: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
127 | while ( it != root ){
| ~~~^~~~~~~
# | 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... |