Submission #237008

#TimeUsernameProblemLanguageResultExecution timeMemory
237008crossing0ver친구 (IOI14_friend)C++17
27 / 100
230 ms65540 KiB
#include<bits/stdc++.h> //#include "friend.h" using namespace std; const int MAXN = 1E5+5; int n,val[MAXN]; vector<int> adj[MAXN]; int dp[MAXN][2]; int case1(){ int mxval = 0; for (int i = 0; i < (1 << n); i++) { vector<int> x; x.clear(); for (int j = 0; j < n; j++) { if ( (1 << j) & i) x.push_back(j); } bool flag = 1; for (int j:x) { for (int k:x) { for (int h : adj[j]) if (h == k) flag = 0; } } if (flag) { int s = 0; for (int j:x) s += val[j]; mxval = max(mxval,s); } } return mxval; } int case2(){ int s = 0; for (int i = 0; i < n; i++) s+= val[i]; return s; } void dfs (int v,int par) { dp[v][0] = val[v]; for (int i: adj[v]) { if (i == par) continue; dfs(i,v); dp[v][1] += dp[i][0]; dp[v][0] += dp[i][1]; } dp[v][0] = max(dp[v][0],dp[v][1]); } int case4() { dfs(1,0); return dp[1][0]; } int findSample(int n1,int confidence[],int host[],int protocol[]){ n = n1; int type[] = {1,1,1}; for (int i =0; i < n; i++) val[i] = confidence[i]; for (int i = 1; i < n; i++) { int x = protocol[i]; int v = host[i]; for (int j =0; j< 3; j++) if (x != j ) type[j] = 0; if (x == 0) { adj[v].push_back(i); adj[i].push_back(v); } else { for (int f:adj[v]) adj[i].push_back(f), adj[f].push_back(i); if (x == 2) { adj[i].push_back(v); adj[v].push_back(i); } } } if (n <= 10) return case1(); if (type[1]) return case2(); if (type[2]) return *max_element(val,val+n); if (type[0]) return case4(); return 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...