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;
int p[2000], mark[2020];
int find (int u) { return u==p[u]? u:p[u]=find(p[u]); }
bool merge (int i, int j) {
// cerr << "merge " << find(i) << ' ' << find(j) << endl;
if (find(i) == find(j)) return false;
p[find(i)] = find(j);
return true;
}
void log (vector<vector<int>> s) {
cerr << "log" << endl;
for (auto x : s) {
for (auto y : x) {
cerr << y << ' ';
} cerr << endl;
}
cerr << endl;
}
int construct(vector<vector<int>> req) {
int n = req.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
iota(p, p+n+1, 0);
int s = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++) {
if (find(i) == find(j)) continue;
if (req[i][j] == 1) {
// cerr << i << ' ' << j << endl;
mark[i] = mark[j] = 1;
answer[j][i] = answer[i][j] = 1;
merge(i, j);
s = i;
}
}
}
// log(answer);
set<int> next;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (req[i][j] == 2) {
if (!mark[i] and !mark[j]) {
next.insert(i);
next.insert(j);
}
}
}
}
int last = s;
for (auto x : next) {
// cerr << x << endl;
answer[s][x] = answer[x][s] = 1;
s = x;
}
if (last != s) answer[last][s] = answer[s][last] = 1;
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... |