Submission #256537

#TimeUsernameProblemLanguageResultExecution timeMemory
256537PedroBigManFriend (IOI14_friend)C++14
46 / 100
43 ms3932 KiB
#include "friend.h" #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <list> #include <iomanip> #include <stdlib.h> #include <time.h> #include <cstring> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++) #define pb push_back #define mp make_pair #define pl pair<ll,ll> #define ff first #define ss second #define whole(x) x.begin(),x.end() #define DEBUG(i) cout<<"Pedro Is The Master "<<i<<endl #define INF 500000000LL #define EPS 0.00000001 #define pi 3.14159 ll mod=99824LL; template<class A=ll> void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;} ll f(ll bin,vector<vector<ll> > adj, ll N,vector<ll> c) { vector<bool> in; REP(i,0,N) {in.pb((bin&(1LL<<i))>0);} REP(i,0,N) { REP(j,i+1,N) { if(in[i]&&in[j]&&(find(whole(adj[i]),j)!=adj[i].end())) {return 0;} } } ll ans=0LL; REP(i,0,N) {if(in[i]) {ans+=c[i];}} return ans; } class Tree { public: ll N; vector<ll> p; vector<vector<ll> > sons; vector<vector<ll> > adj; ll root; vector<bool> visited; vector<ll> val; vector<pl> MIS; //MIS[i].ff=MIS on the i-subtree with i, MIS[i].ss=MIS on the i-subtree without i Tree(vector<vector<ll> > ad, ll r=0LL) { N=ad.size(); root=r; adj=ad; REP(i,0,N) {visited.pb(false);} vector<ll> xx; REP(i,0,N) {sons.pb(xx); p.pb(-1);} DFS_Build(r,r); REP(i,0,N) {MIS.pb(mp(0LL,0LL));} } void Reset() { REP(i,0,N) {visited[i]=false;} } void DFS_Build(ll s, ll par) { p[s]=par; visited[s]=true; REP(i,0,adj[s].size()) { if(adj[s][i]==par) {continue;} sons[s].pb(adj[s][i]); DFS_Build(adj[s][i],s); } return; } void DFS(ll s) { REP(i,0,sons[s].size()) { DFS(sons[s][i]); } MIS[s].ff=val[s]; REP(i,0,sons[s].size()) {MIS[s].ff+=MIS[sons[s][i]].ss;} MIS[s].ss=0LL; REP(i,0,sons[s].size()) {MIS[s].ss+=max(MIS[sons[s][i]].ff,MIS[sons[s][i]].ss);} } }; // Find out best sample int findSample(int n,int confidence[],int host[],int protocol[]) { ll N = (ll) n; vector<ll> c,h,p; REP(i,0,N) {c.pb((ll) confidence[i]); h.pb((ll) host[i]); p.pb((ll) protocol[i]);} if(N<=10LL) { vector<ll> xx; vector<vector<ll> > adj; REP(i,0,N) {adj.pb(xx);} REP(i,1,N) { if(p[i]==0) {adj[i].pb(h[i]); adj[h[i]].pb(i);} else if(p[i]==1) { REP(j,0,adj[h[i]].size()) {ll nei = adj[h[i]][j]; adj[i].pb(nei); adj[nei].pb(i);} } else { REP(j,0,adj[h[i]].size()) {ll nei = adj[h[i]][j]; adj[i].pb(nei); adj[nei].pb(i);} adj[i].pb(h[i]); adj[h[i]].pb(i); } } ll ans=0LL; REP(i,0,(1LL<<N)) {ans=max(ans,f(i,adj,N,c));} return ans; } else if(p[1]==1) { ll sum=0LL; REP(i,0,N) {sum+=c[i];} return sum; } else if(p[1]==2) { return (*max_element(whole(c))); } else if(p[1]==0) { vector<ll> xx; vector<vector<ll> > adj; REP(i,0,N) {adj.pb(xx);} REP(i,1,N) {adj[i].pb(h[i]); adj[h[i]].pb(i);} Tree T(adj); T.val = c; T.DFS(0); return max(T.MIS[0].ff,T.MIS[0].ss); } return 0LL; }
#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...