# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017367 | vivkostov | Friend (IOI14_friend) | C++14 | 0 ms | 0 KiB |
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<bits/stdc++.h>
#define endl '\n'
#include "friend.h"
using namespace std;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long int n,a,b,br[15][15],mas[15],otg,con[15],ho[15],pr[15];
void check()
{
int seg=0;
for(int i=0;i<n;i++)
{
if(!mas[i])continue;
for(int j=i+1;j<n;j++)
{
if(!mas[j])continue;
if(br[i][j])return;
}
seg+=con[i];
}
otg=max(otg,seg);
}
void rec(int step)
{
if(step==n)
{
check();
return;
}
for(int i=0;i<=1;i++)
{
mas[step]=i;
rec(step+1);
}
}
int findSample(int N, int confidence[], int host[], int protocol[])
{
n=N;
for(int i=1;i<n;i++)
{
if(protocol[i]==0)
{
br[host[i]][i]=1;
br[i][host[i]]=1;
}
if(protocol[i]==1)
{
for(int j=0;j<n;j++)
{
br[i][j]=br[host[i]][i];
br[j][i]=br[i][host[i]];
}
}
if(protocol[i]==2)
{
for(int j=0;j<n;j++)
{
br[i][j]=br[host[i]][i];
br[j][i]=br[i][host[i]];
}
br[host[i]][i]=1;
br[i][host[i]]=1;
}
}
for(int i=0;i<n;i++)
{
con[i]=confidence[i];
}
rec(0);
return otg;
}
void read()
{
cin>>n;
for(int i=1;i<n;i++)
{
cin>>ho[i]>>pr[i];
if(pr[i]==0)
{
br[ho[i]][i]=1;
br[i][ho[i]]=1;
}
if(pr[i]==1)
{
for(int j=0;j<n;j++)
{
br[i][j]=br[ho[i]][j];
br[j][i]=br[j][ho[i]];
}
}
if(pr[i]==2)
{
for(int j=0;j<n;j++)
{
br[i][j]=br[ho[i]][j];
br[j][i]=br[j][ho[i]];
}
br[ho[i]][i]=1;
br[i][ho[i]]=1;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<br[i][j]<<" ";
}
cout<<endl;
}
for(int i=0;i<n;i++)
{
cin>>con[i];
}
rec(0);
cout<<otg<<endl;
}
/*int main()
{
speed();
read();
return 0;
}
*/