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 "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
int n, link[1005], sz[1005], link2[1005], sz2[1005];
vector<int> vec[1005], vec2[1005];
int find(int x) {
if (x == link[x]) return x;
return link[x] = find(link[x]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return;
if (sz[b] > sz[a]) swap(a, b);
sz[a] += sz[b];
for (int i : vec[b]) vec[a].pb(i);
link[b] = a;
}
int find2(int x) {
if (x == link2[x]) return x;
return link2[x] = find2(link2[x]);
}
void unite2(int a, int b) {
a = find2(a);
b = find2(b);
if (a == b) return;
if (sz2[b] > sz2[a]) swap(a, b);
sz2[a] += sz2[b];
for (int i : vec2[b]) vec2[a].pb(i);
link2[b] = a;
}
vector<pair<int, int> > tmp;
int construct(vector<vector<int> > p) {
::n = p.size();
vector<vector<int> > b(n, vector<int>(n));
for (int i = 0; i < n; i++) {
link[i] = link2[i] = i;
sz[i] = sz2[i] = 1;
vec[i].pb(i);
vec2[i].pb(i);
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (p[i][j] == 1) unite(i, j);
else if (p[i][j] == 2) tmp.eb(i, j);
}
for (int i = 0; i < n; i++)
if (i == find(i))
for (int j = 0; j < (int)vec[i].size() - 1; j++)
b[vec[i][j]][vec[i][j + 1]] = b[vec[i][j + 1]][vec[i][j]] = 1;
for (auto i : tmp)
unite2(find(i.first), find(i.second));
for (int i = 0; i < n; i++)
if (i == find2(i))
for (int j = 0; j < vec2[i].size(); j++)
b[vec2[i][j]][vec2[i][(j + 1) % vec2[i].size()]] = b[vec2[i][(j + 1) % vec2[i].size()]][vec2[i][j]] = 1;
build(b);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int j = 0; j < vec2[i].size(); j++)
| ~~^~~~~~~~~~~~~~~~
# | 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... |