이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vector<int>> adj(n);
bool two = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) if (p[i][j]) {
two |= p[i][j] == 2;
adj[i].push_back(j);
adj[j].push_back(i);
}
}
vector<int> cc;
vector<bool> vis(n);
function<void(int)> dfs = [&](int u) {
vis[u] = true;
cc.push_back(u);
for (int to : adj[u]) if (!vis[to]) {
dfs(to);
}
};
vector<vector<int>> answer(n, vector<int>(n));
for (int i = 0; i < n; i++) {
if (!vis[i]) {
dfs(i);
int m = cc.size();
int edges = 0;
for (int p : cc)
edges += adj[p].size();
edges /= 2;
if (m == 1)
continue;
if (m == 2 && two)
return 0;
// if (edges >= m)
// return 0;
for (int j = 0; j < m - 1; j++)
answer[cc[j]][cc[j + 1]] = answer[cc[j + 1]][cc[j]] = 1;
if (two)
answer[cc[0]][cc[m - 1]] = answer[cc[m - 1]][cc[0]] = 1;
for (int j = 0; j < m; j++) {
for (int k = 0; k < m; k++) {
if (p[cc[j]][cc[k]] == 0)
return 0;
}
}
cc.clear();
}
}
build(answer);
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... |