This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef set<int> si;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define ALL(x) begin(x), end(x)
#define sz(x) (int)x.size()
vi find_reachable(vi r, vi u, vi v, vi c)
{
int n = sz(r);
int m = sz(c);
vvii adj(n);
loop(m, i)
{
adj[u[i]].pb({v[i], c[i]});
adj[v[i]].pb({u[i], c[i]});
}
vi cnt(n);
loop(n, i)
{
si keys;
vvi edgesPerKey(n);
vb vis(n);
auto addRoom = [&](auto &&self, int room) -> void
{
int key = r[room];
vis[room] = 1;
cnt[i]++;
if (!keys.count(key))
{
keys.insert(key);
for (int j : edgesPerKey[key])
{
if (!vis[j])
self(self, j);
}
}
for (auto [j, keyNeeded] : adj[room])
{
if (vis[j])
continue;
if (keys.count(keyNeeded))
{
self(self, j);
}
else
edgesPerKey[keyNeeded].pb(j);
}
};
addRoom(addRoom, i);
}
int min = *min_element(ALL(cnt));
vi ans(n);
loop(n, i) if (cnt[i] == min) ans[i] = 1;
return ans;
}
# | 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... |