이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
void find_pair(int N, vector<int> U,
vector<int> V, int A, int B) {
int M = U.size();
int lo = 0, hi = M - 1, pos;
vector<int> w(M), ord(M, -1), idx(N);
vector<int> du(N, -1), dv(N, -1);
int init = ask(w);
while (lo <= hi) {
int mi = (lo + hi) / 2;
for (int i = 0; i < M; i++)
w[i] = i <= mi;
if (ask(w) > init) {
pos = mi; hi = mi - 1;
} else lo = mi + 1;
}
vector<vector<int>> adj(N);
for (int i = 0; i < M; i++) {
adj[U[i]].push_back(i);
adj[V[i]].push_back(i);
}
queue<int> que;
que.push(U[pos]); du[U[pos]] = 0;
while (que.size()) {
int u = que.front(); que.pop();
for (auto e : adj[u]) {
int v = u ^ U[e] ^ V[e];
if (du[v] < 0) {
du[v] = du[u] + 1;
que.push(v);
}
}
}
que.push(V[pos]); dv[V[pos]] = 0;
while (que.size()) {
int u = que.front(); que.pop();
for (auto e : adj[u]) {
int v = u ^ U[e] ^ V[e];
if (dv[v] < 0) {
dv[v] = dv[u] + 1;
que.push(v);
}
}
}
vector<int> vis(N);
int cnt = 0;
que.push(U[pos]); vis[U[pos]] = 1;
pair<int, int> ans(U[pos], V[pos]);
while (que.size()) {
int u = que.front(); que.pop();
for (auto e : adj[u]) {
int v = u ^ U[e] ^ V[e];
if (du[v] < dv[v]) {
if (!vis[v]) {
idx[ord[e] = cnt++] = e;
vis[v] = 1; que.push(v);
} else if (du[v] == du[u] + 1)
ord[e] = N;
} else ord[e] = N;
}
}
lo = 0; hi = cnt - 1;
while (lo <= hi) {
int mi = (lo + hi) / 2;
for (int i = 0; i < M; i++)
w[i] = ord[i] >= mi;
if (ask(w) > init) {
if (du[U[idx[mi]]] < du[V[idx[mi]]])
ans.first = V[idx[mi]];
else ans.first = U[idx[mi]];
lo = mi + 1;
} else hi = mi - 1;
}
cnt = 0;
que.push(V[pos]); vis[V[pos]] = 0;
fill(ord.begin(), ord.end(), -1);
while (que.size()) {
int u = que.front(); que.pop();
for (auto e : adj[u]) {
int v = u ^ U[e] ^ V[e];
if (dv[v] < du[v]) {
if (!vis[v]) {
idx[ord[e] = cnt++] = e;
vis[v] = 1; que.push(v);
} else if (dv[v] == dv[u] + 1)
ord[e] = N;
} else ord[e] = N;
}
}
lo = 0; hi = cnt - 1;
while (lo <= hi) {
int mi = (lo + hi) / 2;
for (int i = 0; i < M; i++)
w[i] = ord[i] >= mi;
if (ask(w) > init) {
if (dv[U[idx[mi]]] < dv[V[idx[mi]]])
ans.second = V[idx[mi]];
else ans.second = U[idx[mi]];
lo = mi + 1;
} else hi = mi - 1;
}
answer(ans.first, ans.second);
}
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:27:19: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
27 | que.push(U[pos]); du[U[pos]] = 0;
| ^
# | 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... |