Submission #617313

#TimeUsernameProblemLanguageResultExecution timeMemory
617313happypotatoKeys (IOI21_keys)C++17
9 / 100
119 ms30008 KiB
#include <vector> #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define ff first #define ss second const int mxN = 3e5 + 1; vector<pii> edges[mxN]; vector<int> adj[mxN]; bool vis[mxN], key[mxN]; int val[mxN]; int n, m; void reset() { for (int i = 1; i <= n; i++) { adj[i].clear(); vis[i] = false; key[i] = false; } } void dfs(int u) { vis[u] = true; if (!key[val[u]]) { for (pii &edge : edges[val[u]]) { adj[edge.ff].pb(edge.ss); adj[edge.ss].pb(edge.ff); } key[val[u]] = true; } for (int v : adj[u]) { if (!vis[v]) dfs(v); } } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { n = r.size(); m = c.size(); for (int i = 0; i < n; i++) { r[i]++; } for (int i = 0; i < m; i++) { u[i]++; v[i]++; c[i]++; } for (int i = 1; i <= n; i++) { val[i] = r[i - 1]; } for (int i = 0; i < m; i++) { edges[c[i]].pb({u[i], v[i]}); } if (n <= 2000 && m <= 2000) { int dist[n + 1]; int mini = n + 1; for (int i = 1; i <= n; i++) { reset(); dfs(i); dist[i] = 0; for (int j = 1; j <= n; j++) { dist[i] += vis[j]; } mini = min(mini, dist[i]); } vector<int> ans; for (int i = 1; i <= n; i++) { ans.pb(dist[i] == mini); } return ans; } return {}; }
#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...