Submission #884293

#TimeUsernameProblemLanguageResultExecution timeMemory
884293vjudge1Bosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> #define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define fast_io ios::sync_with_stdio(false);cin.tie(0); #define what(x) cerr << #x << " is " << x << '\n'; #define kill(x) {cout << x << '\n'; return 0;} #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define pb push_back #define ll long long #define F first #define S second const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621; using namespace std; const ll N = 20, LG = 20; vector<int> vec[N]; set<int> adj[N]; int k[N], dp[N], n; ll ans = inf; void dfs (int v) { dp[v] = 1; for (auto u: adj[v]) { dfs(u); dp[v] += dp[u]; } } void bt (int v, int x = 1) { if (x == n + 1) { if (!adj[v].size()) return; dfs(v); ll sum = 0; for (int i = 1; i <= n; i++) sum += dp[i]; if (sum < ans) { ans = sum; // for (int i = 1; i <= n; i++) { // cout << i << ": "; // for (auto u: adj[i]) cout << u << ' '; // cout << '\n'; // } // cout << '\n'; } } if (x == v) { bt(v, x + 1); return; } if (!k[x]) return; for (int i = 0; i < k[x]; i++) { if (adj[vec[x][i]].count(x) || adj[x].count(vec[x][i])) continue; adj[vec[x][i]].insert(x); bt(v, x + 1); adj[vec[x][i]].erase(x); } } int main() { fast_io; cin >> n; for (int i = 1; i <= n; i++) { cin >> k[i]; for (int j = 1; j <= k[i]; j++) { int x; cin >> x; vec[i].pb(x); } } for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) adj[i].clear(); bt(i); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...