이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <random>
#include <vector>
#include <set>
#include <numeric>
#include <cassert>
using namespace std;
vector<vector<int>> adj;
mt19937 gen(123414);
int find(vector<int> vertices, int pivot, set<int> path)
{
if (vertices.size() == 1) return vertices.front();
if (vertices.size() == 2)
{
//do
adj[vertices.front()].push_back(vertices.back());
adj[vertices.back()].push_back(vertices.front());
}
else
{
vector<bool> used(vertices.size());
int left = vertices.size();
int pivot = uniform_int_distribution<>(0, left - 1)(gen);
used[pivot] = true;
--left;
pivot = vertices[pivot];
while (left)
{
int p = uniform_int_distribution<>(1, left)(gen);
for (int i = 0; i < vertices.size(); ++i)
{
p -= !used[i];
if (!p)
{
--left;
used[i] = true;
p = vertices[i];
break;
}
}
vector<int> next{p};
set<int> path;
for (int i = 0; i < vertices.size(); ++i)
{
if (!used[i])
{
int r = Query(vertices[i], p, pivot);
if (r != pivot)
{
used[i] = false;
--left;
next.push_back(vertices[i]);
if (r == vertices[i]) path.insert(r);
}
}
}
int e = find(next, p, path);
adj[pivot].push_back(e);
adj[e].push_back(pivot);
}
}
int v = pivot;
while (!path.empty())
{
bool was = false;
for (int u : adj[v])
{
if (path.find(u) != path.end())
{
path.erase(u);
v = u;
was = true;
}
}
assert(was);
}
return v;
//findPath
}
void Solve(int n)
{
adj.resize(n);
set<int> path;
vector<int> vertices(n);
iota(vertices.begin(), vertices.end(), 0);
find(vertices, 0, path);
for (int i = 0; i < n; ++i)
{
for (int u : adj[i])
{
if (i < u) Bridge(i, u);
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'int find(std::vector<int>, int, std::set<int>)':
meetings.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < vertices.size(); ++i)
| ~~^~~~~~~~~~~~~~~~~
meetings.cpp:46:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i = 0; i < vertices.size(); ++i)
| ~~^~~~~~~~~~~~~~~~~
# | 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... |