이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define TASK ""
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e3 + 5;
const int oo = 1e9;
const long long ooo = 1e18;
const int mod = 1e9 + 7; // 998244353;
const long double pi = acos(-1);
vector <int> s[N];
int ans[N][N];
int a[N][N];
int c[N];
int n,comp;
bool vis[N];
int solve() {
for (int i = 0; i < n; i++) if (!vis[i]) {
queue <int> q({i});
vis[i] = true;
while (q.size()) {
int u = q.front(); q.pop();
s[comp].push_back(u);
c[u] = comp;
for (int v = 0; v < n; v++) if (a[u][v] > 0) {
if (!vis[v]) {
q.push(v);
vis[v] = true;
}
}
}
comp++;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (a[i][j] == 3)
return 0;
for (int i = 0; i < n; i++)
vis[i] = 0;
for (int i = 0; i < comp; i++) {
for (int j : s[i])
for (int k = 0; k < n; k++) {
if (c[j] == c[k] && a[j][k] == 0)
return 0;
if (c[j] != c[k] && a[j][k] > 0)
return 0;
}
vector <int> cir;
for (int j : s[i]) if (!vis[j]) {
int ok = true;
vector <int> tree;
for (int k : s[i])
if (a[j][k] == 1)
tree.push_back(k);
for (int x : tree)
vis[x] = true;
for (int it = 0; it + 1 < (int) tree.size(); it++) {
int u = tree[it];
int v = tree[it + 1];
ans[u][v] = ans[v][u] = 1;
}
for (int x : tree)
for (int y : s[i])
if (!vis[y] && a[x][y] != 2)
return 0;
cir.push_back(tree.back());
}
if (cir.size() == 2)
return 0;
for (int j = 0; j < (int) cir.size(); j++) {
int u = cir[j];
int v = cir[(j + 1) % cir.size()];
ans[u][v] = ans[v][u] = 1;
}
}
return 1;
}
int construct(vector<vector<int>> p) {
n = p.size();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
a[i][j] = p[i][j];
int res = solve();
if (!res)
return 0;
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
for (int j = 0; j < n; j++)
row.push_back(ans[i][j]);
answer.push_back(row);
}
build(answer);
return res;
}
//#include "grader.cpp"
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int solve()':
supertrees.cpp:74:8: warning: unused variable 'ok' [-Wunused-variable]
74 | int ok = true;
| ^~
# | 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... |