This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define sz(x) (ll)x.size()
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
void printVct(vi &v){
cout<<"v: ";
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
vector <vi> arr, adj;
ll n;
vi con, hos, pro;
bool check_set(vi &v){
// cout<<endl;
// printVct(v);
for (ll i =0; i<sz(v); i++){
for (ll j =0; j<sz(v); j++){
// dbg3(v[i],v[j],arr[i][j]);
if (arr[v[i]][v[j]]) return false;
}
}
// printVct(v);
return true;
}
// Find out best sample
int findSample(int N,int cc[],int hh[],int pp[]){
n = N;
for (ll i=0; i<n; i++){
con.pb(cc[i]);
hos.pb(hh[i]);
pro.pb(pp[i]);
}
adj.assign(n,vi());
for (ll i =1; i<n; i++){
ll c = hos[i];
if (pro[i] != 0){
for (ll j = 0; j<sz(adj[c]); j++){
ll d = adj[c][j];
adj[d].pb(i);
adj[i].pb(d);
}
}
if (pro[i] != 1){
adj[c].pb(i);
adj[i].pb(c);
}
}
arr.assign(n, vi(n,0));
for (ll i =0; i<n; i++){
for (ll j =0; j<sz(adj[i]); j++){
arr[i][adj[i][j]] = 1;
}
}
// cout<<endl;
// for (ll i=0; i<n; i++){
// for (ll j =0; j<n; j++){
// cout<<arr[i][j]<<" ";
// }
// cout<<endl;
// }
ll ans = 0;
ll n2 = (1 << n);
for (ll i=0; i<n2; i++){
vi v;
ll c = 0;
for (ll j =0; j<n; j++){
if (i & (1 << j)){
v.pb(j);
c += con[j];
}
}
bool ok = check_set(v);
if (ok){
ans = max(ans, c);
}
}
return ans;
}
/*
3
1 1 1
0 0 0 1
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
6
13 3 6 20 10 15
0 0 0 1 1 2 2 1 0 0
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |