이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 3e5 + 7;
V<pi> G[N];
vi aux[N];
queue<int> q;
bool dead[N], vis[N];
vi find_reachable(vi r, vi _u, vi _v, vi c) {
int n = SZ(r), m = SZ(_u);
for(int i = 0; i < m; i++) {
int u = _u[i], v = _v[i];
G[u].EB(v, c[i]);
G[v].EB(u, c[i]);
}
vi p(n);
auto solve = [&] (int s) {
q.push(s);
auto kill = [&] (int color) {
if(dead[color]) return;
dead[color] = true;
for(int e:aux[color]) q.push(e);
aux[color].clear();
};
auto add = [&] (int color, int v) {
if(dead[color]) q.push(v);
else aux[color].PB(v);
};
int ans = 0;
while(q.size()) {
int u = q.front(); q.pop();
if(vis[u]) continue;
vis[u] = true;
ans++;
kill(r[u]);
for(auto[v, c]:G[u])
add(c, v);
}
q = queue<int>();
for(int i = 0; i < n; i++) {
aux[i].clear();
dead[i] = false;
vis[i] = false;
}
return ans;
};
for(int i = 0; i < n; i++) {
p[i] = solve(i);
}
int mn = *min_element(ALL(p));
vi ans(n);
for(int i = 0; i < n; i++)
ans[i] = p[i] == mn;
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... |