제출 #964545

#제출 시각아이디문제언어결과실행 시간메모리
964545UmairAhmadMirza친구 (IOI14_friend)C++14
46 / 100
24 ms4184 KiB
#include <bits/stdc++.h> using namespace std; int const N=1005; vector<int> adj[N]; int dp[N][2]; void dfs(int node,int par){ for(auto i:adj[node]){ if(i!=par){ dfs(i,node); dp[node][0]+=max(dp[i][1],dp[i][0]); dp[node][1]+=dp[i][0]; } } } int findSample(int n,int confidence[],int host[],int protocol[]){ if(n<=10){ map<pair<int,int>,bool> mp; for (int i = 1; i < n; ++i) { if(protocol[i]==0 || protocol[i]==2){ if(mp[{host[i],i}]) continue; // cout<<i<<' '<<host[i]<<endl; adj[host[i]].push_back(i); adj[i].push_back(host[i]); mp[{host[i],i}]=1; mp[{i,host[i]}]=1; } if(protocol[i]==1 || protocol[i]==2){ for(auto j:adj[host[i]]){ if(mp[{i,j}] || i==j) continue; // cout<<i<<' '<<j<<endl; adj[i].push_back(j); adj[j].push_back(i); mp[{i,j}]=1; mp[{j,i}]=1; } } } int ans=0; for (int mask = 1; mask < (1<<n); ++mask) { bool b=1; for (int i = 0; i < n; ++i) for (int j = i+1; j < n; ++j) if((mask)&(1<<j) && (mask)&(1<<i)) if(mp[{i,j}]) b=0; if(b==0) continue; int t=0; for (int i = 0; i < n; ++i) if(mask&(1<<i)) t+=confidence[i]; // cout<<mask<<' '<<t<<endl; ans=max(ans,t); } return ans; } int ans=0; int maxa=0; for (int i = 0; i < n; ++i){ ans+=confidence[i]; maxa=max(confidence[i],maxa); dp[i][1]=confidence[i]; } if(protocol[1]==2) return maxa; if(protocol[1]==1) return ans; //solve for tree for (int i = 1; i < n; ++i) { adj[host[i]].push_back(i); adj[i].push_back(host[i]); } dfs(0,-1); return max(dp[0][0],dp[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...