이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "keys.h"
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<int>> adj;
vector<int> visited;
int DFS(int index)
{
visited[index] = 1;
int sz = 0;
for (auto node : adj[index])
{
if (visited[node]) continue;
sz += DFS(node);
}
return sz + 1;
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c)
{
N = r.size(); M = u.size();
adj = vector<vector<int>>(N);
for (int i = 0; i < M; i++)
{
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
vector<int> ans(N);
int ok = false;
for (int i = 0; i < N; i++)
{
if (r[i] || adj[i].size() == 0)
{
ans[i] = 1;
ok = true;
}
}
if (ok)
return ans;
visited = vector<int>(N);
int mn_size = 1 << 30;
vector<int> min_components;
for (int i = 0; i < N; i++)
{
if (visited[i]) continue;
int sz = DFS(i);
if (sz < mn_size)
{
min_components = {};
mn_size = sz;
}
if (sz == mn_size)
min_components.push_back(i);
}
visited = vector<int>(N);
for (auto node : min_components)
{
DFS(node);
}
return visited;
}
# | 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... |