# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
386595 | 2021-04-07T04:02:05 Z | milleniumEeee | 바이오칩 (IZhO12_biochips) | C++17 | 12 ms | 10220 KB |
#include <bits/stdc++.h> #define fastInp ios_base::sync_with_stdio(0); cin.tie(0); #define fr first #define sc second #define pii pair<int, int> #define pb push_back #define all(s) s.begin(), s.end() #define szof(s) (int)s.size() using namespace std; const int MAXN = (int)2e5 + 5; vector <int> g[MAXN]; int cost[MAXN]; int tin[MAXN], tout[MAXN], tiktak = 1; void precalc(int v, int par) { tin[v] = ++tiktak; for (int to : g[v]) { if (to != par) { precalc(to, v); } } tout[v] = tiktak; } bool father(int a, int b) { return (tin[a] <= tin[b] && tout[b] <= tout[a]); } signed main() { fastInp; freopen("d.in", "r", stdin); freopen("d.out", "w", stdout); int n, m; cin >> n >> m; int root = -1; for (int i = 1; i <= n; i++) { int par, x; cin >> par >> x; if (!par) { root = i; } else { g[par].pb(i); g[i].pb(par); } cost[i] = x; } precalc(root, -1); int ans = 0; for (int mask = 0; mask < (1 << n); mask++) { int cnt = __builtin_popcount(mask); if (cnt != m) { continue; } vector <int> vec; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { vec.pb(i + 1); } } bool ok = 1; for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (i == j) { continue; } ok &= (!father(vec[i], vec[j])); } } if (ok) { int sum = 0; for (int el : vec) { sum += cost[el]; } ans = max(ans, sum); } } cout << ans << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 12 ms | 10220 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |