이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
//~ #define int ll
vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
int n = r.size();
int m = u.size();
vector<vector<ar<int, 2>>> edges(n);
for(int i=0;i<m;i++){
edges[u[i]].push_back({v[i], c[i]});
edges[v[i]].push_back({u[i], c[i]});
}
int res = n;
vector<int> ans;
vector<int> used(n), cviz(n);
vector<vector<int>> q;
int cnt = 0;
for(int i=0;i<n;i++){
if(r[i] || edges[i].empty()){
used[i] = 1;
res = 0;
}
}
if(!res) return used;
for(int i=0;i<n;i++){
fill(used.begin(), used.end(), 0);
fill(cviz.begin(), cviz.end(), 0);
q.assign(n, vector<int>());
cnt = 0;
queue<int> qq;
qq.push(i);
while(!qq.empty()){
cnt++;
int u = qq.front(); qq.pop();
used[u] = 1;
if(!cviz[r[u]]){
cviz[r[u]] = 1;
for(auto x : q[r[u]]){
if(!used[x]) qq.push(x);
}
}
for(auto [x, c] : edges[u]){
if(used[x]) continue;
if(cviz[c]){
qq.push(x);
} else {
assert(false);
q[c].push_back(x);
}
}
}
if(res > cnt) res = cnt, ans.clear();
if(res == cnt) ans.push_back(i);
}
fill(used.begin(), used.end(), 0);
for(auto x : ans) used[x] = 1;
return used;
}
# | 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... |