이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<ll> vll;
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;
rep (j,0,n-1) {
if (i==j) 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;
}
}
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... |