이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int INF = 5e8, N = 1e5+10, M = 998244353, LOG = 16;
const ll LINF = 1e18;
struct DSU {
vector<int> pr, sz;
DSU (int n) : pr(n), sz(n, 1) {
iota(all(pr), 0);
}
int find_par(int x) {
return pr[x] = (pr[x] == x ? x : find_par(pr[x]));
}
bool unite(int a, int b) {
a = find_par(a), b = find_par(b);
if(a == b) return false;
if(sz[a] < sz[b]) swap(a, b);
pr[b] = a;
sz[a] += sz[b];
return true;
}
};
int construct(vector<vector<int>> p) {
for(const auto& vi : p) if(count(all(vi), 3)) return 0;
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n));
DSU sets(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if(i != j and p[i][j] == 1 and sets.unite(i, j))
ans[i][j] = ans[j][i] = 1;
}
}
set<int> parents;
DSU cmp(n);
for(int i = 0; i < n; ++i)
parents.insert(sets.find_par(i));
while(!parents.empty()) {
vector<int> cur {*parents.begin()};
for(int x : parents)
if(p[cur.back()][x] == 2) {
cur.push_back(x);
cmp.unite(x, cur.back());
}
for(int x : cur) parents.erase(x);
for(int i = 0; i < cur.size(); i++) {
int a = cur[i], b = cur[(i+1)%cur.size()];
if(a != b)
ans[a][b] = ans[b][a] = 1;
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if(p[i][j] == 2) {
if(sets.find_par(i) == sets.find_par(j))
return 0;
if(cmp.find_par(sets.find_par(i)) !=
cmp.find_par(sets.find_par(j)))
return 0;
}
if(p[i][j] == 1 and sets.find_par(i) != sets.find_par(j))
return 0;
if(p[i][j] == 0 and cmp.find_par(sets.find_par(i)) ==
cmp.find_par(sets.find_par(j)))
return 0;
}
build(ans);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 0; i < cur.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |