제출 #313572

#제출 시각아이디문제언어결과실행 시간메모리
313572juggernaut친구 (IOI14_friend)C++14
46 / 100
47 ms4480 KiB
#include"friend.h" //#include"grader.cpp" #include<bits/stdc++.h> using namespace std; vector<int>g[1005],gr[1005]; bool can[15][15]; int dp[1005][2],conf[1005],mt[1005],ans; bool vis[1005],col[1005]; vector<int>v[2]; void add(int x,int y){ g[x].push_back(y); g[y].push_back(x); } void dfs(int v,int p){ dp[v][0]=dp[v][1]=0; dp[v][1]+=conf[v]; for(int to:g[v]) if(to!=p){ dfs(to,v); dp[v][0]+=max(dp[to][0],dp[to][1]); dp[v][1]+=dp[to][0]; } } void go(int vv,int color){ vis[vv]=1; v[color].push_back(vv); col[vv]=color; for(int to:g[vv])if(!vis[to])go(to,1-color); } bool try_kuhn(int v){ if(vis[v])return 0; vis[v]=1; for(int to:g[v]){ if(mt[to]==-1||try_kuhn(to)){ if(mt[to]==-1)ans++; mt[to]=v; return 1; } } return 0; } int findSample(int n,int C[],int host[],int protocol[]){ copy(C,C+n,conf); for(int i=1;i<n;i++){ if(protocol[i]==0){ add(host[i],i); }else if(protocol[i]==1){ for(int to:g[host[i]])add(i,to); }else if(protocol[i]==2){ for(int to:g[host[i]])add(i,to); add(host[i],i); } } if(n<11){ for(int i=0;i<n;i++)for(int to:g[i])can[i][to]=1,can[to][i]=1; int mx=0,sum; for(int mask=0;mask<(1<<n);mask++){ sum=0; for(int i=0;i<n;i++) if(mask>>i&1){ sum+=conf[i]; for(int j=0;j<n;j++)if((mask>>j&1)&&can[i][j])sum=-2e9; } mx=max(mx,sum); } return mx; }else{ int i,cnt[3]={0,0,0}; for(i=1;i<n;i++) cnt[protocol[i]]++; if(cnt[0]==n-1){ dfs(0,0); return max(dp[0][0],dp[0][1]); }else if(cnt[1]==n-1){ int sum=0; for(int i=0;i<n;i++)sum+=conf[i]; return sum; }else if(cnt[2]==n-1){ int sum=0; for(int i=0;i<n;i++)sum=max(sum,conf[i]); return sum; }else{ for(int i=0;i<n;i++)if(!vis[i])go(i,0); for(int to:v[0]){ for(int to2:g[to])if(col[to2]){ gr[to].push_back(to2); gr[to2].push_back(to); } } memset(mt,-1,sizeof(mt)); for(int to:v[0]){ memset(vis,0,sizeof(vis)); try_kuhn(to); } return ans; } } }
#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...