Submission #442979

#TimeUsernameProblemLanguageResultExecution timeMemory
442979benedict0724Keys (IOI21_keys)C++17
37 / 100
126 ms23640 KiB
#include "keys.h" #include <bits/stdc++.h> using namespace std; vector<pair<int, int>> adj[2000]; int Have[2000], visited[2000], R[2000]; stack<int> Next[2000]; int cnt = 0; void dfs(int x) { cnt++; visited[x] = true; Have[R[x]] = 1; for(auto u : adj[x]) { int i = u.first, key = u.second; if(visited[i]) continue; if(Have[key]) dfs(i); else Next[key].push(i); } while(!Next[R[x]].empty()) { int i = Next[R[x]].top(); Next[R[x]].pop(); if(!visited[i]) dfs(i); } } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { int n = r.size(); int m = u.size(); for(int i=0;i<n;i++) R[i] = r[i]; 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]}); } vector<int> ans(n); for(int i=0;i<n;i++) { cnt = 0; for(int j=0;j<n;j++) Have[j] = visited[j] = 0; for(int j=0;j<n;j++) while(!Next[j].empty()) Next[j].pop(); dfs(i); ans[i] = cnt; } int mi = 10000; for(int i=0;i<n;i++) mi = min(ans[i], mi); for(int i=0;i<n;i++) ans[i] = (ans[i] == mi); return ans; }
#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...