#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define f0r(i, n) for (auto i = 0; i < (n); ++i)
#define fnr(i, n, k) for (auto i = (n); i < (k); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define F first
#define S second
#define ctn(x) cout << x << '\n'
#define forl(a, l) for (auto a : l)
#define ctl(l) for (auto &a : (l)) cout << a << ' '; cout << endl;
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define ub(v, x) (upper_bound(all(v), x) - begin(v))
#define pq priority_queue
template <class T>
using V = vector<T>;
using ll = long long;
using vi = V<int>;
using vl = V<ll>;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using Adj = V<V<pi>>;
using vvi = V<vi>;
Adj G;
void dfs(int v, V<bool> &vis, vi &out) {
vis[v] = 1;
out.pb(v);
for (auto &[c, w]: G[v]) if (!vis[c]) dfs(c, vis, out);
}
vi find_reachable(vi r, vi u, vi v, vi c) {
int n = r.size(), m = c.size();
vi ans(n);
G = Adj(n);
f0r(i, m) {
G[u[i]].pb({v[i], c[i]});
G[v[i]].pb({u[i], c[i]});
}
vi sz(n);
f0r(i, n) {
V<bool> vis(n), fnd(n);
V<vi> ned(n);
queue<int> Q;
Q.push(i);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
if (vis[u]) continue;
++sz[i];
vis[u] = 1;
fnd[r[u]] = 1;
forl(x, ned[r[u]]) if (!vis[x]) Q.push(x);
for (auto &[v, w]: G[u]) if (!vis[v]) {
if (fnd[w]) Q.push(v);
else ned[w].pb(v);
}
}
}
int mn = *min_element(all(sz));
f0r(i, n) if (sz[i] == mn) ans[i] = 1;
return ans;
}