제출 #129346

#제출 시각아이디문제언어결과실행 시간메모리
129346antimirage친구 (IOI14_friend)C++14
35 / 100
6 ms504 KiB
#include "friend.h" //#include "grader.cpp" #include <bits/stdc++.h> #define fr first #define sc second #define mk make_pair #define pb push_back #define all(s) s.begin(), s.end() using namespace std; const int N = 1005; vector <int> g[N]; int a[N], dp[N][2], u[N], sum1, sum2; void dfs (int v, int p = -1) { dp[v][1] = a[v]; for (auto to : g[v]) { if (to == p) continue; dfs(to, v); dp[v][1] += dp[to][0]; dp[v][0] += max(dp[to][0], dp[to][1]); } } void dfs2 (int v, int color) { u[v] = 1; if (color) sum1 += a[v]; else sum2 += a[v]; for (auto to : g[v]) { if (u[to]) continue; dfs2(to, color ^ 1); } } int findSample(int n, int val[], int batya[], int type[]) { int ans = 0; bool fl = 1; for (int i = 0; i < n; i++) { if (val[i] != 1) { fl = 0; } } if (fl) { a[0] = val[0]; for (int i = 1; i < n; i++) { a[i] = val[i]; if (type[i] == 0) { g[batya[i]].pb(i); g[i].pb(batya[i]); } else if (type[i] == 1) { for (auto it: g[batya[i]]) { g[i].pb(it); g[it].pb(i); } } else { g[batya[i]].pb(i); g[i].pb(batya[i]); for (auto it: g[batya[i]]) { g[i].pb(it); g[it].pb(i); } } } for (int i = 0; i < n; i++) { if (u[i]) continue; sum1 = sum2 = 0; dfs2(i, 0); ans += max(sum1, sum2); } } else if (type[1] == 1) { for (int i = 0; i < n; i++) { ans += val[i]; } } else if (type[1] == 2) { for (int i = 0; i < n; i++) { ans = max(ans, val[i]); } } else { a[0] = val[0]; for (int i = 1; i < n; i++) { assert(batya[i] < i); g[batya[i]].pb(i); g[i].pb(batya[i]); a[i] = val[i]; } dfs(0); ans = max(dp[0][0], dp[0][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...
#Verdict Execution timeMemoryGrader output
Fetching results...