# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
798206 | HaroldVemeno | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 186 ms | 23616 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<vector<int>> am;
vector<vector<int>> res;
vector<int> comp;
int compn = 0;
vector<int> tv;
int tvn = 0;
int construct(vector<vector<int>> p) {
n = p.size();
am = std::move(p);
comp.resize(n, -1);
res.resize(n, vector<int>(n, 0));
tv.resize(n, -1);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(am[i][j] == 3) {
return 0;
}
if(am[i][j] != am[j][i]) {
return 0;
}
}
}
for(int i = 0; i < n; ++i) {
if(am[i][i] != 1) return 0;
res[i][i] = 1;
}
vector<vector<int>> comps;
for(int i = 0; i < n; ++i) {
if(comp[i] != -1) continue;
comp[i] = compn++;
comps.push_back({i});
for(int j = 0; j < n; ++j) {
if(i == j) continue;
if(am[i][j] > 0) {
comp[j] = comp[i];
comps[comp[i]].push_back(j);
}
}
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if((comp[i] == comp[j]) != (am[i][j] > 0)) {
return 0;
}
}
}
vector<vector<int>> tvbycomps(compn);
vector<vector<int>> ts;
for(int i = 0; i < n; ++i) {
if(tv[i] != -1) continue;
tv[i] = tvn++;
ts.push_back({i});
tvbycomps[comp[i]].push_back(i);
for(int j = 0; j < n; ++j) {
if(i == j) continue;
if(am[i][j] == 1) {
tv[j] = tv[i];
res[i][j] = 1;
res[j][i] = 1;
ts[tv[i]].push_back(j);
}
}
}
for(auto& c : comps) {
for(int a : c) {
for(int b : c) {
if((tv[a] == tv[b]) != (am[a][b] == 1)) {
return 0;
}
if((tv[a] != tv[b]) != (am[a][b] == 2)) {
return 0;
}
}
}
}
for(auto& cts : tvbycomps) {
if(cts.size() == 1) continue;
if(cts.size() == 2) return 0;
for(int i = 0; i < cts.size()-1; ++i) {
res[cts[i]][cts[i+1]] = 1;
res[cts[i+1]][cts[i]] = 1;
}
res[cts[0]][cts.back()] = 1;
res[cts.back()][cts[0]] = 1;
}
for(int i = 0; i < n; ++i) {
res[i][i] = 0;
}
build(res);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |