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"
#define rep(i,a,b) for(int i=a;i<int(b);i++)
#define rrep(i,a,b)for(int i=a;i>int(b);i--)
#define all(v) v.begin(),v.end()
#define trav(a,v) for(auto& a: v)
typedef long long ll;
using namespace std;
const long long inf = 1e15;
vector<ll> p(2001);
vector<ll> Rank(2001);
ll Ufindset(ll i) {
if (p[i] == i)return i;
return p[i] = Ufindset(p[i]);
}
void UjoinSet(ll i, ll j) {
ll si = Ufindset(i);
ll sj = Ufindset(j);
if (sj == si)return;
if ( Rank[sj]> Rank[si])swap(sj, si);
p[sj] = si;
if (Rank[sj] == Rank[si]) Rank[si]++;
}
int construct(vector<vector<int>> v) {
rep(i, 0, 2001)p[i] = i;
vector<vector<int>> b(v.size(), vector<int>(v.size()));
if (v[0][1] != 2) {
rep(i, 0, v.size()) {
ll root = -1;
rep(j, 0, v.size()) {
if (v[i][j]) {
if (root == -1)if (p[j] != j)root = p[j];
if (root != -1)if (p[j] != root)return 0;
UjoinSet(i, j);
}
else if (p[j] == p[i]) return 0;
}
}
rep(i, 0, v.size()) {
if (p[i] != i) {
b[i][p[i]] = 1;
b[p[i]][i] = 1;
}
}
}
else {
rep(i, 0, v.size()) {
b[i][(i + 1) % v.size()] = 1;
b[(i + 1) % v.size()][i] = 1;
}
}
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... |