# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
589917 | Dan4Life | 친구 (IOI14_friend) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LOL
#if !defined(LOL)
#include "friend.h"
#endif
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int maxn = (int)2e5+10;
vector<int> adj[maxn];
set<int> S;
void add_edge(int a, int b){
adj[a].pb(b); adj[b].pb(a);
}
bool chk(int s){
for(auto u : adj[s])
if(S.count(u)) return false;
return true;
}
int findSample(int n, int c[], int h[], int pro[])
{
for(int i = 1; i < n; i++){
if(pro[i]==1 or pro[i]==3)
add_edge(h[i],i);
else if(pro[i]!=1)
for(auto u : adj[h[i]]) add_edge(u,i);
}
vector<int> v(n-1,0); int cnt = 0;
for(auto &u : v) u = cnt++;
//iota(all(v),0);
int ans = 0;
do{
int sum = 0; S.clear();
for(auto u : v)
if(chk(u)) sum+=c[u], S.insert(u);
ans = max(ans, sum);
}while(next_permutation(all(v)));
return ans;
}
#if defined(LOL)
int main(void)
{
#define __MAXSIZE__ 100002
int confidence[__MAXSIZE__];
int host[__MAXSIZE__];
int protocol[__MAXSIZE__];
int n,i;
// Number of people
assert(scanf("%d",&n)==1);
// Confidence
for(i=0;i<n;i++)
assert(scanf("%d",&confidence[i])==1);
// Host and Protocol
for(i=1;i<n;i++)
assert(scanf("%d %d",&host[i],&protocol[i])==2);
// Answer
printf("%d\n",findSample(n,confidence,host,protocol));
return 0;
}
#endif