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 rep(i,s,e) for (int i = s; i <= e; ++i)
typedef vector<int> vi;
int construct (vector<vi> p) {
int n = p.size();
int sup[n], tree[n], spec[n];
memset(sup,-1,4*n), memset(tree,-1,4*n);
rep (i,0,n-1) {
if (sup[i]==-1) {
bool two = 0;
rep (j,0,n-1) {
if (p[i][j]==3) return 0;
if (p[i][j]==1 || p[i][j]==2) {
if (sup[i]==-1) sup[i] = sup[j] = j;
else sup[j] = sup[i];
if (p[i][j]==1) {
if (tree[i]==-1) tree[i] = tree[j] = j;
else tree[j] = tree[i];
}
else two = 1;
}
else if (i==j) return 0;
}
spec[sup[i]] = !two;
}
else if (tree[i]==-1) {
rep (j,0,n-1) {
if (p[i][j]==3) return 0;
if (p[i][j]==1 || p[i][j]==2) {
if (p[sup[i]][j] != 1 && p[sup[i]][j] != 2) return 0;
if (p[i][j]==1) {
if (tree[i]==-1) tree[i] = tree[j] = j;
else tree[j] = tree[i];
}
}
else if (p[sup[i]][j]) return 0;
}
}
else rep (j,0,n-1) if (p[tree[i]][j]!=p[i][j]) return 0;
}
vector<vi> b(n,vi(n,0));
rep (i,0,n-1) {
if (i==sup[i]) {
int last = i, cnt = 0;
rep (j,0,n-1) {
if (sup[j]==i && j==tree[j]) cnt++;
if (i==j || sup[j]!=i) continue;
if (j==tree[j]) {
if (spec[i]) continue;
b[j][last] = b[last][j] = 1;
last = j;
}
else b[j][tree[j]] = b[tree[j]][j] = 1;
}
if (last!=i && !spec[i]) b[last][i] = b[i][last] = 1;
if (!spec[i] && cnt==2) 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... |