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>
#define ll long long
#define ff first
#define ss second
using namespace std;
const int N = 2222;
vector<pair<int, int> > g[N];
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c)
{
int n = r.size(), m = c.size();
vector<int> ans(n, 0);
for (int i = 0; i < m; i++){
g[u[i]].emplace_back(v[i], c[i]);
g[v[i]].emplace_back(u[i], c[i]);
}
vector<int> p(n, 0);
for (int i = 0; i < n; i++){
queue<int> q;
vector<bool> used(n, false), keys(n, false);
used[i] = true;
keys[r[i]] = true;
q.push(i);
while (!q.empty()){
int x = q.front();
q.pop();
p[i]++;
for (auto e : g[x]){
int y = e.ff, C = e.ss;
if (!used[y] && keys[C]){
keys[r[y]] = true;
used[y] = true;
q.push(y);
}
}
}
}
int mn = *min_element(p.begin(), p.end());
for (int i = 0; i < n; i++){
if (p[i] == mn) ans[i] = 1; else
ans[i] = 0;
}
assert(count(ans.begin(), ans.end(), 1) > 1);
return ans;
}
/**
4 5
0 1 1 2
0 1 0
0 2 0
1 2 1
1 3 0
3 1 2
*/
# | 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... |