이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
constexpr static int SIZE = 300000;
constexpr static int MX = 1e6;
vector<array<int, 2>> g[SIZE];
vector<int> pending_nodes[SIZE];
bitset<SIZE> processed;
int visited[SIZE];
int keys[SIZE];
vector<int> pending_keys;
int counts[SIZE];
vector<int> visited_list;
vector<int> r;
int min_count = MX;
int bfs(int node)
{
queue<int> q;
q.push(node);
int counter = 0;
while (q.size())
{
int j = q.front();
q.pop();
counter++;
visited[j] = node;
visited_list.pb(j);
if (processed[j] || counter > min_count)
return MX;
if (keys[r[j]] != node)
{
keys[r[j]] = node;
for (int c : pending_nodes[r[j]])
{
if (visited[c] != node)
{
visited[c] = node;
q.push(c);
}
}
}
for (auto [c, k] : g[j])
{
if (visited[c] == node)
continue;
if (keys[k] != node)
{
if (pending_nodes[k].empty())
pending_keys.pb(k);
pending_nodes[k].pb(c);
}
else
{
visited[c] = node;
q.push(c);
}
}
}
return counter;
}
void process(int node)
{
int res = bfs(node);
processed[node] = true;
for (int i : pending_keys)
pending_nodes[i].clear();
pending_keys.clear();
min_count = min(res, min_count);
for (int i : visited_list)
counts[i] = min(counts[i], res);
visited_list.clear();
}
vector<int> find_reachable(vector<int> rr, vector<int> u, vector<int> v, vector<int> c)
{
r = rr;
int n = r.size(), m = u.size();
for (int i = 0; i < m; i++)
{
g[v[i]].pb({u[i], c[i]});
g[u[i]].pb({v[i], c[i]});
}
for (int i = 0; i < n; i++)
{
visited[i] = -1;
keys[i] = -1;
counts[i] = MX;
}
vector<int> ordering(n);
for (int i = 0; i < n; i++)
ordering[i] = i;
shuffle (ordering.begin(), ordering.end(), default_random_engine(242345));
for (int i : ordering)
process(i);
vector<int> res(n, 0);
for (int i = 0; i < n; i++)
if (counts[i] == min_count)
res[i] = 1;
return res;
}
# | 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... |