#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
struct DSU{
int n;
vector<int> par, s;
DSU(int N){
n = N;
s.assign(n, 1), par.resize(n);
iota(all(par), 0);
}
int get(int a){
return par[a] = (a == par[a] ? a : get(par[a]));
}
void uni(int a, int b){
a = get(a), b = get(b);
if(s[a] > s[b])swap(a, b);
par[a] = b, s[b] += s[a];
}
int get_size(int a){
return s[get(a)];
}
bool same_set(int a, int b){
return get(a) == get(b);
}
};
const int N = 1005;
vector<int> adj[N], adj2[N];
vector<int> component;
bool vis[N];
void dfs(int u){
component.pb(u);
vis[u] = true;
for(int v: adj[u])if(!vis[d.get(v)])dfs(d.get(v));
}
int construct(vector<vector<int>> p){
int n = sz(p);
vector<vector<int>> ans(n, vector<int>(n, 0));
forn(i,n)adj[i].clear(), adj2[i].clear();
DSU d(n);
DSU fuck(n);
for(int i = 0;i < n; ++i){
for(int j = 0;j < n; ++j){
if(i == j)continue;
if(p[i][j] != p[j][i])return 0;
}
}
for(int i = 0;i < n; ++i){
vis[i] = false;
for(int j = 0;j < n; ++j){
if(p[i][j] == 2 && i != j){
adj[i].pb(j);
}
if(p[i][j] == 1 && i != j){
if(!d.same_set(i, j)){
d.uni(i, j);
ans[i][j] = ans[j][i] = 1;
}
}
}
}
for(int i = 0;i < n; ++i){
if(!vis[d.get(i)]){
component.clear();
dfs(i);
if(sz(component) == 2)return 0;
for(int i = 0;i < sz(component); ++i){
if(sz(component) > 1)ans[component[i]][component[(i + 1) % sz(component)]] = ans[component[(i + 1) % sz(component)]][component[i]] = 1;
fuck.uni(component[i], component[(i + 1) % sz(component)]);
}
}
}
for(int i = 0;i < n; ++i){
for(int j = 0;j < n; ++j){
if(i == j)continue;
if(ans[i][j] && !p[i][j])return 0;
if(fuck.same_set(i, j) && !p[i][j])return 0;
if(d.same_set(i, j) && !p[i][j])return 0;
}
}
for(int i = 0;i < n; ++i){
adj[i].clear();
adj2[i].clear();
vis[i] = false;
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:50:31: error: 'd' was not declared in this scope
50 | for(int v: adj[u])if(!vis[d.get(v)])dfs(d.get(v));
| ^