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>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x)
#define rmax(r, x) r = max(r, x)
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 1e3 + 10;
int n, pa[maxn];
bool chk[maxn];
vector<vector<int>> b;
int fnd(int x) { return (pa[x] < 0 ? x : pa[x] = fnd(pa[x])); }
void uni(int a, int b) {
a = fnd(a), b = fnd(b);
if(a == b) return;
pa[a] = b;
}
int construct(vector<std::vector<int>> p) {
memset(pa, -1, sizeof(pa));
n = p.size();
b.resize(n);
for(int i = 0; i < n; ++i) b[i].resize(n);
for(int i = 0; i < n; ++i) if(!chk[i]) {
vector<int> v;
for(int j = i + 1; j < n; ++j) if(p[i][j]) v.eb(j);
if(v.size() < 2) return 0;
chk[i] = true;
int prev = i;
for(auto& j : v) {
chk[j] = true;
uni(prev, j);
b[prev][j] = b[j][prev] = 1;
prev = j;
}
b[prev][i] = b[i][prev] = 1;
}
for(int i = 0; i < n; ++i) for(int j = i + 1; j < n; ++j) {
if(!p[i][j] && fnd(i) == fnd(j)) return 0;
if(p[i][j] && fnd(i) != fnd(j)) return 0;
}
build(b);
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... |