이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"supertrees.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
vvi L;
vi K, K3;
vi F;
int find(int a) {return (F[a] == -1 ? a : F[a] = find(F[a]));}
void uunion(int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
F[a] = b;
}
int oink(vvi p) {
int n = p.size();
vvi Adj(n, vi(n, 0));
L.clear(); F.clear(); F.resize(n, -1);
K.clear(); K.resize(n, -1); K3.clear(); K3.resize(n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (p[i][j]) {
if (p[i][j] == 1) K[i] = j;
if (p[i][j] == 3) K3[i] = 1;
uunion(i, j);
continue;
}
//cerr << i << " " << j << " " << find(i) << " " << find(j) << endl;
if (find(i) == find(j)) return 0;
}
}
L.resize(n);
for (int i = 0; i < n; i++) {
L[find(i)].push_back(i);
}
//cerr << endl;
for (auto i : L) {
/*
for (auto j : i) {
cerr << j << " ";
}
cerr << endl;
//*/
if (i.size() < 2) continue;
if (i.size() == 2) {
int a = i[0], b = i[1];
if (p[a][b] >= 2) return 0;
Adj[a][b] = 1;
Adj[b][a] = 1;
continue;
}
int l = i[i.size()-1];
bool q = K3[l];
//cerr << q << endl;
int l3 = -1;
for (int j = 0; j < i.size(); j++) {
int a = i[j];
if (q != K3[a]) return 0;
//cerr << l << " " << a << " " << K[a] << " " << j << endl;
if (l == a) break;
if (K[a] <= a) {
if (q && l == l3 && a == i[i.size()-1]) return 0;
Adj[l][a] = 1;
Adj[a][l] = 1;
if (q && l3 == -1 && l != i[i.size()-1]) {
Adj[a][i[i.size()-1]] = 1;
Adj[i[i.size()-1]][a] = 1;
l3 = a;
}
l = a;
continue;
}
Adj[K[a]][a] = 1;
Adj[a][K[a]] = 1;
if (q && l3 == -1) return 0;
}
}
build(Adj);
return 1;
}
int oinkoink(vvi p) {
int n = p.size();
vvi Adj(n, vi(n, 0));
F.clear(); F.resize(n, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j]) {
if (find(i) == find(j)) continue;
Adj[i][j] = 1;
Adj[j][i] = 1;
uunion(i, j);
continue;
}
//cerr << i << " " << j << " " << find(i) << " " << find(j) << endl;
if (find(i) == find(j)) return 0;
}
}
build(Adj);
return 1;
}
int construct(std::vector<std::vector<int>> p) {
return oink(p);
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int oink(std::vector<std::vector<int> >)':
supertrees.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int j = 0; j < i.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... |