제출 #316914

#제출 시각아이디문제언어결과실행 시간메모리
316914shivensinha4친구 (IOI14_friend)C++17
19 / 100
3 ms2816 KiB
#include <bits/stdc++.h> #include "friend.h" using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' const int MXN = 1e5; vi adj[MXN+1]; int val[MXN+1], dp[MXN+1][3], id[MXN+1]; // [][0] -> exclude root; [][1] -> no restriction void dfs(int p, int parent) { dp[p][1] = val[p]; for (int i: adj[p]) if (i != parent) { dfs(i, p); dp[p][0] += dp[i][1]; dp[p][1] += dp[i][0]; } dp[p][1] = max(dp[p][1], dp[p][0]); } int findSample(int n, int confidence[], int host[], int protocol[]) { for_(i, 0, n) { val[i] = confidence[i]; id[i] = i; } for_(i, 1, n) { if (protocol[i] == 0) adj[host[i]].push_back(i); else if (protocol[i] == 1) { val[host[i]] += val[i]; id[i] = host[i]; } else { val[host[i]] = max(val[host[i]], val[i]); id[i] = host[i]; } } dfs(0, 0); return dp[0][1]; } //int main() { //#ifdef shiven //freopen("test.in", "r", stdin); //#endif //ios_base::sync_with_stdio(false); //cin.tie(0); //int n = 6; //int confidence[] = {13, 3, 6, 20, 10, 15}; //int protocol[] = {-1, 0, 1, 2, 1, 0}; //int host[] = {-1, 0, 0, 1, 2, 0}; //cout << findSample(n, confidence, host, protocol) << endl; //return 0; //}
#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...