이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
#define all(v) v.begin(),v.end()
#define sort(v) sort(all(v))
#define endl '\n'
#define forn(i,n) for(int i = 0; i < n; ++i)
#define forbe(i,b,e) for(int i = b; i < e; ++i)
#define forr(i,n) for(int i = n-1; i >= 0; --i)
#define sz(v) ((int)v.size())
#define pb push_back
#define f first
#define s second
void build(vector<vi> b);
const int N = 1e3;
int par[N];
int lst[N];
int siz[N];
vi adj[N];
int getp(int x) { return par[x] = (par[x] == x ? x : getp(par[x])); }
int getl(int x) { return lst[x] = (lst[x] == x ? x : getl(lst[x])); }
int uni(int a, int b) {
a = getp(a);
b = getp(b);
if (a == b) return 0;
adj[a].pb(getl(b));
adj[getl(b)].pb(a);
par[a] = b;
siz[b] += siz[a];
lst[getl(b)] = getl(a);
lst[b] = getl(a);
return 1;
}
int construct(vector<vi> p) {
int n = sz(p);
bool t0, t1, t2;
t0 = t1 = t2 = 0;
int task = 0;
forn(i,n) {
forn(j,n) {
if (p[i][j] == 0) t0 = 1;
if (p[i][j] == 1) t1 = 1;
if (p[i][j] == 2) t2 = 1;
}
}
if (t1 && !t2) task = 1;
if (t2 && !t1) task = 2;
if (t2 && t1) task = 3;
forn(i,n) par[i] = i;
forn(i,n) lst[i] = i;
forn(i,n) siz[i] = 1;
forn(i,n) {
forn(j,n) {
if (i == j) continue;
if (p[i][j])
uni(i,j);
}
}
forn(i,n) {
forn(j,n) {
if (i == j) continue;
if (p[i][j] == 0 && getp(i) == getp(j))
return 0;
}
}
vector<vi> ans(n);
forn(i,n)
ans[i].assign(n,0);
if (task == 2) {
forn (i, n) {
if (getp(i) != i) continue;
if (siz[getp(i)] == 2) return 0;
adj[i].pb(getl(i));
adj[getl(i)].pb(i);
}
}
forn (i,n) {
for (int u : adj[i])
ans[i][u] = 1;
}
build(ans);
return 1;
}
#ifdef ONPC
void build(vector<vi> b) {
}
void solve() {
}
int main() {
// freopen("in", "r", stdin);
// ios_base::sync_with_stdio(0);cin.tie(0);
solve();
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:50:10: warning: variable 't0' set but not used [-Wunused-but-set-variable]
50 | bool t0, t1, t2;
| ^~
# | 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... |