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 <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int MAX_N = 1e3 + 5;
int n;
vector <int> graph[MAX_N];
bool visited[MAX_N];
vector <vector <int>> answer;
int cmp[MAX_N];
int parent[MAX_N];
vector <int> nodes[MAX_N];
int root(int u) {
if(u == parent[u]) {
return u;
}
return parent[u] = root(parent[u]);
}
void dfs(int u) {
visited[u] = true;
for(auto v : graph[u]) {
if(visited[v] == false) {
cmp[v] = cmp[u];
answer[u][v] = answer[v][u] = 1;
dfs(v);
}
}
}
int construct(vector <vector <int>> p) {
n = p.size();
answer.resize(n, vector <int> (n, 0));
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(p[i][j] == 1) {
graph[i].push_back(j);
graph[j].push_back(i);
}
}
}
for(int i = 0; i < n; i++) {
if(visited[i] == false) {
visited[i] = true;
cmp[i] = i;
dfs(i);
}
}
iota(parent, parent + n, 0);
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
if(p[i][j] == 2) {
parent[root(cmp[j])] = root(cmp[i]);
}
}
}
for(int i = 0; i < n; i++) {
if(cmp[i] == i) {
nodes[root(i)].push_back(i);
}
}
for(int i = 0; i < n; i++) {
if(root(i) == i and i == cmp[i] and nodes[i].size() > 1) {
int p = nodes[i].back();
for(auto v : nodes[i]) {
answer[v][p] = answer[p][v] = 1;
p = v;
}
}
}
build(answer);
return 1;
}
# | 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... |