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 <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <cmath>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
using namespace std;
#define all(x) x.begin(),x.end()
const int mx = 300005;
void find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) {
//Graph implementatiom
vector<vector<pair<int , int > > > adj(mx);
for(int i=0; i <u.size(); i++){
pair<int, int> vv;
vv.first = v[i];
vv.second = c[i];
adj[u[i]].push_back(vv);
vv.first = u[i];
vv.second = c[i];
adj[v[i]].push_back(vv);
}
//BFS && DP
vector<int> conected(r.size());
vector<vector<int> > hash(r.size());
for(int j = 0; j<r.size(); j++){
vector<bool> visited(r.size() , false);
int source = j;
queue<int> qu;
qu.push(source);
int cnt= 0;
hash[source].push_back(r[source]);
while(!qu.empty()){
int cur = qu.front();
qu.pop();
visited[cur] = true;
cnt += 1;
for(pair<int , int > i : adj[cur]){
if(count(hash[source].begin() , hash[source].end() , i.second) != 0 && visited[i.first] == false){
hash[source].push_back(r[i.first]);
visited[i.first] = true;
qu.push(i.first);
}
}
}
conected[j] = cnt;
}
vector<int> ans(r.size() , 0);
int uu = *min_element(conected.begin() , conected.end());
for(int i=0; i<r.size(); i++){
if(conected[i] == uu) ans[i] = 1;
}
for(int i : ans)cout << i << " ";
cout << endl;
}
/*
#1
4
0 1 1 2
5
0 0 1 1 3
1 2 2 3 1
0 0 1 0 2
#2
3
0 0 0
1
0
1
0
#3
7
0 1 1 2 2 1 2
10
0 0 1 1 2 3 3 4 4 5
1 2 2 3 3 4 5 5 6 6
0 0 1 0 0 1 2 0 2 1
*/
// int main(){
// int n; cin >> n;
// vector<int> r(n);
// for(int &i : r) cin >> i;
// int m; cin >> m;
// vector<int> u(m);
// vector<int> v(m);
// for(int &i : u) cin >> i;
// for(int &i : v) cin >> i;
// vector<int> c(m);
// for(int &i : c) cin >> i;
// find_reachable(r , u , v, c);
// return 0;
// }
Compilation message (stderr)
keys.cpp: In function 'void find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0; i <u.size(); i++){
| ~~^~~~~~~~~
keys.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int j = 0; j<r.size(); j++){
| ~^~~~~~~~~
keys.cpp:87:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=0; i<r.size(); i++){
| ~^~~~~~~~~
# | 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... |