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>
#include "keys.h"
using namespace std;
const int MXN = 3e5 + 5;
int n;
vector<array<int, 2>> adj[MXN];
vector<int> r, c;
int arr[MXN], used[MXN];
set<int> skey;
map<int, vector<int>> snode;
void addnode(int x, int &node);
void addkey(int x, int &node)
{
skey.insert(x);
if (snode[x].empty()) return;
vector<int> &v = snode[x];
while (!v.empty())
{
int x = v.back();
v.pop_back();
addnode(x, node);
}
}
void addnode(int x, int &node)
{
if (used[x]) return;
// cout << x << ' ';
if (!used[x]) arr[node]++;
used[x] = 1;
addkey(r[x], node);
for (array<int, 2> &v : adj[x])
{
if (skey.find(v[1]) != skey.end()) addnode(v[0], node);
else snode[v[1]].push_back(v[0]);
}
}
void process(int x)
{
fill(used, used + n, 0);
snode.clear(), skey.clear();
// cout << x << ": ";
addnode(x, x);
// cout << '\n';
}
vector<int> find_reachable(vector<int> R, vector<int> u, vector<int> v, vector<int> C)
{
n = R.size(), r = R, c = C;
for (int i = 0; i < u.size(); i++)
{
adj[u[i]].push_back({v[i], c[i]});
adj[v[i]].push_back({u[i], c[i]});
}
for (int i = 0; i < n; i++)
{
process(i);
}
int mn = *min_element(arr, arr + n);
vector<int> res(n, 0);
for (int i = 0; i < n; i++) res[i] = (arr[i] == mn);
return res;
}
Compilation message (stderr)
keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
# | 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... |