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"
#include "friend.h"
using namespace std;
vector<set<int>> adj;
set<int> em;
set<int> denied;
vector<int> c;
int dfs(int u, int n)
{
int r = c[u];
int temp = c[u];
denied.insert(u);
for(auto v: adj[u])
denied.insert(v);
for(int i = 0; i<n; i++)
{
if(!denied.count(i))
{
int val = dfs(i, n);
r = max(r, temp + val);
}
}
return r;
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
c.resize(n);
for(int i = 0; i<n; i++)
c[i] = confidence[i];
adj.assign(n, em);
for(int i = 1; i<n; i++)
{
if(protocol[i]==0)
{
int x = host[i];
adj[x].insert(i);
adj[i].insert(x);
}
else if(protocol[i]==1)
{
int x = host[i];
for(auto v: adj[x])
{
adj[v].insert(i);
adj[i].insert(v);
}
}
else
{
int x = host[i];
adj[x].insert(i);
adj[i].insert(x);
for(auto v: adj[x])
{
adj[v].insert(i);
adj[i].insert(v);
}
}
}
int res = 0;
for(int i = 0; i<n; i++)
{
denied.clear();
int maxi = dfs(i, n);
res = max(res, maxi);
}
return res;
}
# | 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... |