# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
361705 | cuongdh1912 | Highway Tolls (IOI18_highway) | C++14 | 214 ms | 9552 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#if not LOCAL
#define NDEBUG
#endif
#include<cassert>
#include<vector>
#include<cstdint>
#include<algorithm>
#include <array>
#include <queue>
using namespace std;
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = (int)U.size();
vector<int> w;
w.resize(M, 0);
const auto d = ask(w);
int i = 0;
// find the maximum of index where there is no shortest path has edge in 0..<i
// therefore there must be an edge index i the shortest path have
for (auto step = 1<<20; step>>=1;) {
if (i + step < M) {
w.assign(i+step, 1);
w.resize(M, 0);
if (d == ask(w)) {
i += step;
}
}
}
struct Edge { int node, index;};
vector<vector<Edge> > add(N);
for (int j = 0; j < M; ++j) {
int a = U[j]; int b = V[j];
add[a].push_back({b, j});
add[b].push_back({a, j});
}
array<vector<Edge>, 2> edges;
edges[0].push_back({U[i], i});
edges[1].push_back({V[i], i});
vector<bool> visited(M, false);
visited[edges[0][0].node] = true;
visited[edges[1][0].node] = true;
for (int j = 0; j < edges.size(); ++j) {
// find maximum
queue<int> q;
q.push(edges[j][0].node);
while (q.size() > 0) {
int v = q.front(); q.pop();
for (auto e: add[v]) {
if (!visited[e.node]) {
visited[e.node] = true;
q.push(e.node);
edges[j].push_back(e);
}
}
}
}
int ans[2];
for (int j = 0; j < edges.size(); ++j ) {
int k = (int)edges[j].size();
for (int step = 1<<20; step>>=1; ) {
if (k - step > 0) {
w.assign(M, 1);
w[i] = 0;
for (int l = 0; l < k - step; ++l) w[edges[j][l].index] = 0;
for (int l = 0; l < edges[!j].size(); ++l ) w[edges[!j][l].index] = 0;
if (d == ask(w)) {
k -= step;
}
}
}
ans[j] = edges[j][k-1].node;
}
answer(ans[0], ans[1]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |