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>
using namespace std;
int N,*C,*H,*P;
vector <int> conection[100000];
bool visited[100000];
void connect(int a,int b)
{
conection[a].push_back(b);
conection[b].push_back(a);
}
void prijatelstva()
{
int i;
for (i=1; i<N; i++)
{
if(P[i]==0)
{
connect(H[i],i);
}
if(P[i]==1)
{
for(int j=conection[H[i]].size(); j--;)
connect(conection[H[i]][j], i);
}
if(P[i]==2)
{
for(int j=conection[H[i]].size(); j--;)
connect(conection[H[i]][j], i);
connect(H[i], i);
}
}
}
int dfs(int n, int val)
{
int i, rez=0;
if(n==N)
return val;
for (i=conection[n].size(); i--;)
{
if(visited[conection[n][i]])
break;
}
if(i<0)
{
visited[n]=1;
rez=dfs(n+1, val+C[n]);
}
visited[n]=0;
int v=dfs(n+1, val);
if(v>rez)
rez=v;
return rez;
}
int subtask1()
{
prijatelstva();
memset(visited, false, sizeof(visited));
return dfs(0, 0);
}
int subtask2()
{
int zbir=0, i;
for (i=0; i<N; i++)
zbir+=C[i];
return zbir;
}
int subtask3()
{
int maxx=-1, i;
for (i=0; i<N; i++)
{
if(C[i]>maxx)
maxx=C[i];
}
return maxx;
}
int findSample(int n, int confidence[], int host[], int protocol[])
{
int i;
N=n;
C=confidence;
H=host;
P=protocol;
if (N<=10)
return subtask1();
for(i=2; i<N; i++)
if(protocol[i-1]!=protocol[i])
break;
if(i>=N)
{
if(protocol[1]==1)
return subtask2();
if(protocol[1]==2)
return subtask3();
}
return 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... |