This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (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);
}
Compilation message (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... |