Submission #441794

#TimeUsernameProblemLanguageResultExecution timeMemory
441794baluteshihKeys (IOI21_keys)C++17
37 / 100
3060 ms33188 KiB
#include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define X first #define Y second #define pb push_back #define ALL(v) v.begin(), v.end() #define SZ(a) ((int)a.size()) vector<int> G[300005]; vector<pii> road[300005]; int conn[300005], vis[300005]; vector<int> stk; void dfs(int u, vector<int> &r) { if (!vis[r[u]]) stk.pb(r[u]), vis[r[u]] = 1; conn[u] = 1; for (int i : G[u]) if (!conn[i]) dfs(i, r); } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { int n = SZ(r), m = SZ(u); vector<int> ans(n, 0); vector<int> arr(n, 0); for (int i = 0; i < m; ++i) road[c[i]].pb(pii(u[i], v[i])); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) vis[j] = conn[j] = 0, G[j].clear(); dfs(i, r); while (!stk.empty()) { int clr = stk.back(); stk.pop_back(); for (pii e : road[clr]) { if (conn[e.X] && conn[e.Y]) continue; if (conn[e.X] || conn[e.Y]) { if (!conn[e.X]) dfs(e.X, r); if (!conn[e.Y]) dfs(e.Y, r); continue; } G[e.X].pb(e.Y); G[e.Y].pb(e.X); } } for (int j = 0; j < n; ++j) arr[i] += conn[j]; } int mi = *min_element(ALL(arr)); for (int i = 0; i < n; ++i) if (arr[i] == mi) ans[i] = 1; 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...