제출 #518705

#제출 시각아이디문제언어결과실행 시간메모리
518705amukkalir친구 (IOI14_friend)C++17
19 / 100
3 ms3532 KiB
#include "friend.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; #define pb push_back const int nax = 1e5; int dp[nax+5][2]; int c[nax+5]; vector<int> adj[nax+5]; int n; int f(int u, int b) { int &ret = dp[u][b]; if(~ret) return ret; ret = 0; if(adj[u].size() == 0) { ret = b ? c[u] : 0; } else { int a = 0, g = 0; for(int v : adj[u]) { a += f(v, 1); if(b) { g += f(v, 0); } } if(b) g += c[u]; ret = max(a, g); } //cout << u << " " << b << " " << ret << endl; return ret; } // Find out best sample int findSample(int N,int confidence[],int host[],int protocol[]){ n = N; memset(dp, -1, sizeof dp); c[0] = confidence[0]; for(int i=1; i<N; i++) { //cout << i << " " << host[i] << endl; c[i] = confidence[i]; adj[host[i]].pb(i); } return max(f(0,0), f(0,1)); }
#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...