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 "keys.h"
//#include <cassert>
//#include <cstdio>
//#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
vector<int> bekle[N], vis(N), col(N);
vector<pair<int, int> > adj[N];
std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c){
std::vector<int> ans(r.size(), 1);
int n = r.size();
int m = u.size();
for(int i = 0; i < m; i++){
adj[u[i]].push_back({v[i], c[i]});
adj[v[i]].push_back({u[i], c[i]});
}
int mn = N;
for(int i = 0; i < n; i++){
queue<int> q;
q.push(i);
col[r[i]] = 1;
int calc = 0;
while(!q.empty()){
int x = q.front();
q.pop();
if(vis[x]) continue;
vis[x] = 1;
//cout<<i<<" -> "<<x<<endl;
calc++;
for(auto itr: bekle[r[x]]){
if(!vis[itr]){
q.push(itr);
col[r[itr]] = 1;
}
}
bekle[r[x]].clear();
for(auto itr: adj[x]){
if(vis[itr.first]) continue;
if(!col[itr.second]){
bekle[itr.second].push_back(itr.first);
}
else{
col[r[itr.first]] = 1;
q.push(itr.first);
}
}
}
for(int j = 0; j < n; j++){
vis[j] = col[j] = 0;
bekle[j].clear();
}
mn = min(mn, calc);
ans[i] = calc;
}
for(int i = 0; i < n; i++){
if(ans[i] == mn) ans[i] = 1;
else ans[i] = 0;
}
return ans;
}
/*
int main(){
int n, m;
assert(2 == scanf("%d%d", &n, &m));
std::vector<int> r(n), u(m), v(m), c(m);
for(int i=0; i<n; i++) {
assert(1 == scanf("%d", &r[i]));
}
for(int i=0; i<m; i++) {
assert(3 == scanf("%d %d %d", &u[i], &v[i], &c[i]));
}
fclose(stdin);
std::vector<int> ans = find_reachable(r, u, v, c);
for (int i = 0; i < (int) ans.size(); ++i) {
if(i) putchar(' ');
putchar(ans[i]+'0');
}
printf("\n");
return 0;
}
*/
# | 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... |