이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5 + 5;
vector<array<int, 2> > g[N];
vector<int> key_types;
int n, m;
vector<int32_t> solve1()
{
vector<int32_t> ans;
int current_count = 1e18;
for(int i = 0; i < n; i++)
{
int total_count = 0;
vector<int> colors[n + 1];
vector<bool> already_found(n + 1, false), vis(n + 1, false);
vis[i] = true;
queue<int> q;
q.push(i);
while(!q.empty())
{
int node = q.front();
total_count += 1;
q.pop();
already_found[key_types[node]] = true;
for(int to: colors[key_types[node]])
{
if(vis[to]) continue;
vis[to] = true;
q.push(to);
}
colors[key_types[node]].clear();
for(auto [to, req]: g[node])
{
if(vis[to]) continue;
if(already_found[req])
{
vis[to] = true;
q.push(to);
}
colors[req].push_back(to);
}
}
if(total_count < current_count)
{
ans.clear();
current_count = total_count;
}
if(total_count == current_count)
{
ans.push_back(i);
}
}
return ans;
}
vector<int32_t> find_reachable(vector<int32_t> r, vector<int32_t> u,
vector<int32_t> v, vector<int32_t> c)
{
n = r.size(), m = c.size();
vector<int32_t> ans(n, 0);
for(int i = 0; i < n; i++)
{
key_types.push_back(r[i]);
}
for(int i = 0; i < m; i++)
{
g[u[i]].push_back({v[i], c[i]});
g[v[i]].push_back({u[i], c[i]});
}
if(n <= 2000 and m <= 2000)
{
vector<int32_t> cur_ans = solve1();
for(int i: cur_ans)
{
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... |