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 <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
const int mxN = 3e5 + 1;
vector<pii> edges[mxN];
vector<int> adj[mxN];
bool vis[mxN], key[mxN];
int val[mxN];
int n, m;
void reset() {
for (int i = 1; i <= n; i++) {
adj[i].clear();
vis[i] = false;
key[i] = false;
}
}
void dfs(int u) {
vis[u] = true;
if (!key[val[u]]) {
for (pii &edge : edges[val[u]]) {
adj[edge.ff].pb(edge.ss);
adj[edge.ss].pb(edge.ff);
}
key[val[u]] = true;
}
for (int v : adj[u]) {
if (!vis[v]) dfs(v);
}
}
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
n = r.size();
m = c.size();
for (int i = 0; i < n; i++) {
r[i]++;
}
for (int i = 0; i < m; i++) {
u[i]++;
v[i]++;
c[i]++;
}
for (int i = 1; i <= n; i++) {
val[i] = r[i - 1];
}
for (int i = 0; i < m; i++) {
edges[c[i]].pb({u[i], v[i]});
}
if (n <= 2000 && m <= 2000) {
int dist[n + 1];
int mini = n + 1;
for (int i = 1; i <= n; i++) {
reset();
dfs(i);
dist[i] = 0;
for (int j = 1; j <= n; j++) {
dist[i] += vis[j];
}
mini = min(mini, dist[i]);
}
vector<int> ans;
for (int i = 1; i <= n; i++) {
ans.pb(dist[i] == mini);
}
return ans;
}
return {};
}
# | 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... |