제출 #386595

#제출 시각아이디문제언어결과실행 시간메모리
386595milleniumEeee바이오칩 (IZhO12_biochips)C++17
0 / 100
12 ms10220 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

biochips.cpp: In function 'int main()':
biochips.cpp:34:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  freopen("d.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
biochips.cpp:35:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 |  freopen("d.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...