Submission #834767

#TimeUsernameProblemLanguageResultExecution timeMemory
834767IS_RushdiKeys (IOI21_keys)C++17
20 / 100
3050 ms2097152 KiB
#include <bits/stdc++.h> using namespace std; vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { vector<int> ans(r.size(), 1); int n = r.size(); int m = u.size(); vector<vector<vector<int>>>a(n,vector<vector<int>>(n,vector<int>())); for(int i = 0; i < m; i++){ a[u[i]][c[i]].push_back(v[i]); a[v[i]][c[i]].push_back(u[i]); } vector<int>tmp(n); int mn = 1e9; for(int i = 0; i < n; i++){ vector<bool>vis(n,0); vector<int>nodes; vector<bool>key(n,0); set<int>keys; queue<int>q; q.push(i); while(!q.empty()){ int node = q.front(); q.pop(); if(vis[node]) continue; vis[node]=1; nodes.push_back(node); int k = r[node]; if(!key[k]){ for(int x : nodes){ for(int to : a[x][k]){ q.push(to); } } } for(int k : keys){ for(int to : a[node][k]){ q.push(to); } } keys.insert(k); key[k]=1; } tmp[i] = nodes.size(); mn = min(mn,tmp[i]); } for(int i = 0; i < n; i++){ if(tmp[i] == mn) ans[i] = 1; else ans[i] = 0; } return ans; } // int main(){ // int n; cin >> n; // vector<int>a(n); // for(int i = 0; i < n; i++) cin >> a[i]; // int m; cin >> m; // vector<int>b(m),c(m),d(m); // for(int i = 0; i < m; i++) cin >> b[i]; // for(int i = 0; i < m; i++) cin >> c[i]; // for(int i = 0; i < m; i++) cin >> d[i]; // vector<int>ans = find_reachable(a,b,c,d); // for(int i = 0; i < n; i++) cout << ans[i] << ' '; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...