이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
inline void myBridge(int x, int y) {
if(x > y) swap(x, y);
//cerr << x << " " << y << "\n";
Bridge(x, y);
}
void solve(vector <int> &nodes, int par) {
int n = nodes.size();
if(n == 1) {
myBridge(par, nodes[0]);
n--;
}
if(n == 0) return ;
vector < pair <int, int> > arr;
vector <int> path;
int nod = nodes[rand() % n];
for(auto it : nodes) {
if(it == nod) continue;
int cur = Query(par, it, nod);
if(cur == it) {
if(cur != par && cur != nod)
path.push_back(cur);
}
else {
arr.push_back({cur, it});
}
}
sort(path.begin(), path.end());
path.resize(unique(path.begin(), path.end()) - path.begin());
sort(arr.begin(), arr.end());
/*cerr << par << " " << nod << "\n";
for(auto it : arr) {
cerr << it.second << " ";
}
cerr << "\n";*/
if(path.empty()) {
myBridge(par, nod);
}
else {
sort(path.begin(), path.end(), [&](const int &x, const int &y) {
return Query(par, x, y) == x;
});
myBridge(par, path[0]);
for(int i = 0; i + 1 < path.size(); i++) {
myBridge(path[i], path[i + 1]);
}
myBridge(path.back(), nod);
}
int i = 0;
while(i < arr.size()) {
vector <int> aux;
int j = i;
while(j < arr.size() && arr[i].first == arr[j].first) {
aux.push_back(arr[j].second);
j++;
}
solve(aux, arr[i].first);
//cerr << j << " " << arr.size() << "\n";
i = j;
}
}
void Solve(int n) {
srand(time(NULL));
vector <int> nodes(n - 1);
iota(nodes.begin(), nodes.end(), 1);
solve(nodes, 0);
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'void solve(std::vector<int>&, int)':
meetings.cpp:53:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i + 1 < path.size(); i++) {
~~~~~~^~~~~~~~~~~~~
meetings.cpp:60:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(i < arr.size()) {
~~^~~~~~~~~~~~
meetings.cpp:63:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < arr.size() && arr[i].first == arr[j].first) {
~~^~~~~~~~~~~~
# | 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... |