# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
902973 | Muhammad_Aneeq | Friend (IOI14_friend) | C++17 | 1071 ms | 34484 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 <vector>
#include <iostream>
#include <set>
#include "friend.h"
using namespace std;
int const N=2000;
int ed[N][N]={};
int vis[N]={};
int ans=0;
int nn;
int val[N]={};
int cur[N]={};
void dfs(int i,int val1)
{
vis[i]=1;
for (int j=0;j<nn;j++)
cur[j]=cur[j]+(ed[i][j]==0);
for (int j=0;j<nn;j++)
{
if (ed[i][j]&&!vis[j]&&cur[j]==0)
dfs(j,val1+val[j]);
}
vis[i]=0;
for (int j=0;j<nn;j++)
cur[j]=cur[j]-(ed[i][j]==0);
ans=max(ans,val1);
}
int findSample(int n,int confidence[],int host[],int protocol[])
{
nn=n;
for (int i=0;i<n;i++)
val[i]=confidence[i];
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
ed[i][j]=1;
set<int>s;
for (int i=1;i<n;i++)
{
s.insert(protocol[i]);
if (protocol[i]==0)
ed[i][host[i]]=ed[host[i]][i]=0;
else if (protocol[i]==1)
{
for (int j=0;j<n;j++)
{
if (ed[host[i]][j]==0)
ed[i][j]=ed[j][i]=0;
}
}
else
{
ed[i][host[i]]=ed[host[i]][i]=0;
for (int j=0;j<n;j++)
{
if (ed[host[i]][j]==0)
ed[i][j]=ed[j][i]=0;
}
}
}
if (s.size()==1&&*begin(s)==1)
{
int ans=0;
for (int i=0;i<n;i++)
ans+=val[i];
return ans;
}
for (int i=0;i<n;i++)
dfs(i,val[i]);
return ans;
}
Compilation message (stderr)
# | 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... |