#include <bits/stdc++.h>
using namespace std;
const int NMAX=2007;
int cnt[3],vis[NMAX],w[NMAX],dp[NMAX][2];
vector<int> g[NMAX];
int ans=0;
void dfs(int son, int par)
{
vis[son]=1;
ans=max(ans,w[son]);
for(int i:g[son]) if(!vis[i]) dfs(i,son);
}
void dfs1(int son,int par)
{
vis[son]=1;
dp[son][1]=w[son];
for(int i:g[son])
{
if(vis[i]) continue;
dfs1(i,son);
dp[son][0]+=max(dp[i][0],dp[i][1]);
dp[son][1]+=dp[i][0];
}
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
//cin>>n;
//for(int i=0;i<n;i++) cin>>confidence[i], w[i]=confidence[i];
for(int i=0;i<n;i++) w[i]=confidence[i];
for(int i=1;i<n;i++)
{
//cin>>host[i]>>protocol[i];
int tmp=protocol[i];
if(tmp==0)
{
cnt[0]++;
g[host[i]].push_back(i);
g[i].push_back(host[i]);
}
if(tmp==1)
{
cnt[1]++;
for(int j:g[host[i]])
{
g[i].push_back(j);
g[j].push_back(i);
}
}
else
{
cnt[2]++;
g[host[i]].push_back(i);
g[i].push_back(host[i]);
for(int j:g[host[i]])
{
if(i==j) continue;
g[i].push_back(j);
g[j].push_back(i);
}
}
}
if(n<=10)
{
int res=0;
for(int mask=1;mask<(1<<n);mask++)
{
vector<int> tmp;
for(int i=0;i<n;i++) if(mask&(1<<i)) tmp.push_back(i);
int ok=1;
for(int i:tmp)
{
for(int j:tmp)
{
if(i==j) continue;
for(int t:g[i]) if(t==j) ok=0;
}
}
int ans=0;
if(ok) for(int i:tmp) ans+=confidence[i];
if(ok) res=max(res,ans);
}
return res;
}
if(cnt[2]==n-1)
{
int res=0;
ans=0;
for(int i=0;i<n;i++) if(!vis[i]){dfs(i,0); res+=ans;}
return res;
}
if(cnt[1]==n-1)
{
int res=0;
for(int i=0;i<n;i++) res+=w[i];
return res;
}
if(cnt[0]==n-1)
{
int res=0;
for(int i=0;i<n;i++) if(!vis[i]){dfs1(i,0); res+=max(dp[i][0],dp[i][1]);}
return res;
}
}
Compilation message
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:109:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
12 ms |
4224 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
11 ms |
3200 KB |
Output is correct |
5 |
Correct |
16 ms |
4224 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
896 KB |
Output is correct |
8 |
Correct |
4 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
16 ms |
4452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |