이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int maxn = 1002;
int dsu[3][maxn];
set <int> comp [3][maxn];
int get_dad (int x, int d[]) {
return d[x] = (x == d[x] ? x: get_dad(d[x], d));
}
void merge (int a, int b, int d[]){
a = get_dad(a, d);
b = get_dad(b, d);
d[b] = a;
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector <vector <int> > b (n, vector <int> (n));
for (int i = 0; i < n; i++){
dsu[0][i] = dsu[1][i] = dsu[2][i] = i;
comp[1][i].insert(i);
comp[2][i].insert(i);
}
for (int i = 0; i < n; i++){
for (int j = 0; j < i; j++){
merge(i,j, dsu[p[i][j]]);
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < i; j++){
// if (p[i][j] == 0 && (get_dad(i, dsu[1]) == get_dad(j, dsu[1]) || get_dad(i, dsu[2]) == get_dad(j, dsu[2]))) return 0;
// if (p[i][j] == 1 && get_dad(i, dsu[2]) == get_dad(j, dsu[2])) return 0;
// if (p[i][j] == 2 && get_dad(i, dsu[1]) == get_dad(j, dsu[1])) return 0;
if (p[i][j] == 1) comp[1][get_dad(i, dsu[1])].insert(j);
if (p[i][j] == 2) comp[2][get_dad(i, dsu[2])].insert(j);
}
}
for (int i = 0; i < n; i++){
if (comp[1][i].size() != 1) {
// cout << "1 " << i << ": ";
vector <int> v;
for (int j: comp[1][i]) {
// cout << j << " ";
v.push_back(j);
}
// cout << "\n";
for (int j = 0; j < v.size() - 1; j++){
b[v[j]][v[j + 1]] = b[v[j + 1]][v[j]] = 1;
}
}
if (comp[2][i].size() != 1){
if (comp[2][i].size() == 2) return 0;
// cout << "2 " << i << ": ";
vector <int> v;
for (int j: comp[2][i]) {
// cout << j << " ";
v.push_back(j);
}
// cout << "\n";
for (int j = 0; j < v.size(); j++){
b[v[j]][v[(j + 1) % v.size()]] = b[v[(j + 1) % v.size()]][v[j]] = 1;
}
}
}
// for (int i = 0; i < n; i++){
// for (int j = 0; j <i; j++){
// if (b[i][j]) {
// cout << j << " " << i << "\n";
// }
// }
// }
build(b);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int j = 0; j < v.size() - 1; j++){
| ~~^~~~~~~~~~~~~~
supertrees.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int j = 0; j < v.size(); j++){
| ~~^~~~~~~~~~
# | 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... |