이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "split.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> graph[100000];
vector<pair<int, int>> lab;
bool in_a[100000];
int cmp[100000], cmp_sz[100000];
int find(int A) {
while (A != cmp[A]) A = cmp[A], cmp[A] = cmp[cmp[A]];
return A;
}
void onion(int A, int B) {
if (find(A) != find(B)) {
cmp_sz[find(A)] += cmp_sz[find(B)];
cmp[find(B)] = find(A);
}
}
bool possible() {
queue<int> q;
q.push(0);
in_a[0] = true;
for (int cnt = 1; cnt < lab[0].first;) {
int curr = q.front();
q.pop();
for (int i : graph[curr]) {
if (!in_a[i] && cnt < lab[0].first) {
in_a[i] = true;
q.push(i);
cnt++;
}
}
}
iota(cmp, cmp + n, 0);
fill(cmp_sz, cmp_sz + n, 1);
for (int i = 0; i < n; i++) if (!in_a[i]) {
for (int j : graph[i]) if (!in_a[j]) onion(i, j);
}
for (int i = 0; i < n; i++) {
if (!in_a[i] && cmp_sz[find(i)] >= lab[0].first) return true;
}
return false;
}
vector<int> find_split(int N, int a, int b, int c, vector<int> p, vector<int> q) {
n = N;
lab = {{a, 1}, {b, 2}, {c, 3}};
sort(lab.begin(), lab.end());
for (int i = 0; i < p.size(); i++) {
graph[p[i]].push_back(q[i]);
graph[q[i]].push_back(p[i]);
}
if (!possible()) return vector<int>(n, 0);
return vector<int>(n, 1);
}
컴파일 시 표준 에러 (stderr) 메시지
split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:53:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < p.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |