이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
vector<vector<pair<int, int>>> g;
long long cur;
int M;
int calc(int v, vector<int> t) {
int tl = 0, tr = t.size() - 1, ans = v;
vector<int> get(M, 0);
while (tl <= tr) {
int tm = tl + tr >> 1;
for (auto &i : get) i = 0;
for (int i = tm + 1; i < t.size(); ++i) {
for (auto to : g[t[i]])
get[to.second] = 1;
}
if (ask(get) == cur) {
ans = t[tm];
tr = tm - 1;
}
else {
tl = tm + 1;
}
}
return ans;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
M = U.size();
vector<int> activ;
vector<int> get(M, 0);
vector<int> was(N, 0);
g = vector<vector<pair<int, int>>> (N, vector<pair<int, int>>(0));
cur = ask(get);
for (int i = 0; i < M; ++i) {
g[V[i]].push_back({U[i], i});
g[U[i]].push_back({V[i], i});
}
int tl = 0, tr = M, ans = -1;
while (tl <= tr) {
int tm = tl + tr >> 1;
for (int i = 0; i < M; ++i)
get[i] = (i > tm);
if (ask(get) == cur) {
ans = tm;
tr = tm - 1;
}
else {
tl = tm + 1;
}
}
queue<int> q;
vector<int> d(N, -1), col(N, 0);
vector<int> is[2];
q.push(U[ans]), q.push(V[ans]);
d[U[ans]] = d[V[ans]] = 0;
col[U[ans]] = 0;
col[V[ans]] = 1;
while (q.size()) {
int v = q.front();
q.pop();
is[col[v]].push_back(v);
for (auto it : g[v]) {
int to = it.first, c = it.second;
if (d[to] == -1) {
d[to] = d[v] + 1;
col[to] = col[v];
q.push(to);
}
}
}
int a = calc(U[ans], is[0]);
int b = calc(V[ans], is[1]);
answer(a, b);
return;
}
컴파일 시 표준 에러 (stderr) 메시지
highway.cpp: In function 'int calc(int, std::vector<int>)':
highway.cpp:15:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
15 | int tm = tl + tr >> 1;
| ~~~^~~~
highway.cpp:17:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = tm + 1; i < t.size(); ++i) {
| ~~^~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:45:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
45 | int tm = tl + tr >> 1;
| ~~~^~~~
highway.cpp:68:23: warning: unused variable 'c' [-Wunused-variable]
68 | int to = it.first, c = it.second;
| ^
# | 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... |