이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include "supertrees.h"
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> matrix;
int find(vector<int>& p, int x) {
return p[x] == x ? x : (p[x] = find(p, p[x]));
}
void merge(vector<int>& p, int x, int y) {
p[find(p, x)] = find(p, y);
}
int construct(vector<vector<int>> p) {
int n = sz(p);
vector<vector<int>> ret;
for(int i = 0; i < n; i++) {
vector<int> t(n);
ret.pb(t);
}
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 3) return 0;
vector<int> connectedcomponent(n);
iota(all(connectedcomponent), 0);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j]) merge(connectedcomponent, i, j);
// check zero
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 0 && find(connectedcomponent, i) == find(connectedcomponent, j)) return 0;
// check one
vector<int> oneedge(n);
iota(all(oneedge), 0);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(p[i][j] == 1) merge(oneedge, i, j);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
if(p[i][j] == 0) continue;
if(p[i][j] != 1 && find(oneedge, i) != find(oneedge, j)) return 0;
}
map<int, int> treetoroot;
for(int i = 0; i < n; i++) {
if(!treetoroot.count(find(oneedge, i))) {
treetoroot[find(oneedge, i)] = i;
}
else {
ret[treetoroot[find(oneedge, i)]][i] = 1;
ret[i][treetoroot[find(oneedge, i)]] = 1;
}
}
map<int, set<int>> roots;
for(int i = 0; i < n; i++) {
roots[find(connectedcomponent, i)].insert(treetoroot[find(oneedge, i)]);
}
for(auto out: roots) {
cerr << out.f << " has roots:";
for(auto out2: out.s) cerr << " " << out2; cerr << endl;
if(sz(out.s) == 2) return 0;
if(sz(out.s) == 1) continue;
vector<int> v(all(out.s));
for(int i = 0; i < sz(v); i++) {
int j = (i+1)%sz(v);
ret[v[i]][v[j]] = 1;
ret[v[j]][v[i]] = 1;
}
}
build(ret);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:83:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
83 | for(auto out2: out.s) cerr << " " << out2; cerr << endl;
| ^~~
supertrees.cpp:83:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
83 | for(auto out2: out.s) cerr << " " << out2; cerr << endl;
| ^~~~
# | 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... |