이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "keys.h"
#define ff first
#define ss second
using namespace std;
typedef pair<int, int> pii;
const int maxn = 2e3+10;
int a[maxn];
int ans[maxn];
vector<pii> grafo[maxn];
vector<int> edge[maxn];
bool mark[maxn];
void bfs(int s)
{
memset(mark, 0, sizeof mark);
set<int> st;
set<pii> ord;
st.insert(a[s]);
edge[a[s]].push_back(s);
ord.insert({1, a[s]});
while (ord.size())
{
pii pp = *ord.begin();
ord.erase(pp);
if (pp.ff-1 > 0) ord.insert({pp.ff-1, pp.ss});
int u = edge[pp.ss].back();
edge[pp.ss].pop_back();
if (st.find(a[u]) == st.end() && edge[a[u]].size() > 0)
ord.insert({edge[a[u]].size(), a[u]});
st.insert(a[u]);
if (!mark[u]) ans[s]++;
else continue;
mark[u] = 1;
for (auto pp: grafo[u])
{
int v = pp.ff, w = pp.ss;
edge[w].push_back(v);
if (ord.find({(int)edge[w].size()-1, w}) != ord.end())
ord.erase({(int)edge[w].size()-1, w});
if (st.find(w) != st.end()) ord.insert({edge[w].size(), w});
}
}
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c)
{
int n = r.size(), m = u.size();
for (int i = 1; i <= n; i++)
a[i] = r[i-1]+1;
for (int i = 0; i < m; i++)
{
grafo[u[i]+1].push_back({v[i]+1, c[i]+1});
grafo[v[i]+1].push_back({u[i]+1, c[i]+1});
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
edge[j].clear();
bfs(i);
}
vector<int> final;
int mn = *min_element(ans+1, ans+n+1);
for (int i = 1; i <= n; i++)
{
if (ans[i] == mn) final.push_back(1);
else final.push_back(0);
}
return final;
}
# | 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... |