#include "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000;
bool matr[MAX_N][MAX_N];
vector<int> graph[MAX_N];
void buildGraph(int n, int *host, int *protocol) {
for(int i = 1; i < n; ++i) {
if(protocol[i] == 0)
matr[i][host[i]] = matr[host[i]][i] = true;
else if(protocol[i] == 1) {
for(int j = 0; j < n; ++j)
if(matr[host[i]][j])
matr[i][j] = matr[j][i] = true;
} else {
matr[i][host[i]] = matr[host[i]][i] = true;
for(int j = 0; j < n; ++j)
if(matr[host[i]][j])
matr[i][j] = matr[j][i] = true;
}
}
for(int i = 0; i < n; ++i)
matr[i][i] = false;
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(matr[i][j])
graph[i].push_back(j);
}
int subtask2(int n, int *confidence, int *host, int *protocol) {
int sum = 0;
for(int i = 0; i < n; ++i)
sum += confidence[i];
return sum;
}
int subtask3(int n, int *confidence, int *host, int *protocol) {
int rez = 0;
for(int i = 0; i < n; ++i)
rez = max(rez, confidence[i]);
return rez;
}
int dp[MAX_N][2];
void dfs(int *confidence, int nod, int papa = -1) {
dp[nod][1] = confidence[nod];
for(auto it: graph[nod])
if(it != papa) {
dfs(confidence, it, nod);
dp[nod][1] += dp[it][0];
dp[nod][0] += max(dp[it][0], dp[it][1]);
}
}
int subtask4(int n, int *confidence, int *host, int *protocol) {
buildGraph(n, host, protocol);
dfs(confidence, 0);
return max(dp[0][0], dp[0][1]);
}
bool viz[MAX_N];
vector<int> bip[2];
void dfs(int nod, int color = 0) {
viz[nod] = true;
bip[color].push_back(nod);
for(auto it: graph[nod])
if(!viz[it])
dfs(it, 1 - color);
}
int subtask5(int n, int *confidence, int *host, int *protocol) {
buildGraph(n, host, protocol);
dfs(0);
return max(bip[0].size(), bip[1].size());
}
// Find out best sample
int findSample(int n,int confidence[],int host[],int protocol[]){
int rez = 0;
if(n <= 10) {
buildGraph(n, host, protocol);
for(int mask = 0; mask < (1 << n); ++mask) {
int sum = 0;
bool ok = true;
for(int i = 0; i < n; ++i) {
if((1 << i) & mask)
sum = sum + confidence[i];
for(int j = 0; j < n; ++j)
if(((1 << i) & mask) != 0 && ((1 << j) & mask) != 0 && matr[i][j])
ok = false;
}
if(ok)
rez = max(rez, sum);
}
} else {
int nr[3];
nr[0] = nr[1] = nr[2] = 0;
for(int i = 1; i < n; ++i)
nr[protocol[i]]++;
if(nr[0] == 0 && nr[1] == n - 1 && nr[2] == 0)
rez = subtask2(n, confidence, host, protocol);
else if(nr[0] == 0 && nr[1] == 0 && nr[2] == n - 1)
rez = subtask3(n, confidence, host, protocol);
else if(nr[0] == n - 1 && nr[1] == 0 && nr[2] == 0)
rez = subtask4(n, confidence, host, protocol);
else if(nr[2] == 0)
rez = subtask5(n, confidence, host, protocol);
}
return rez;
}
# |
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 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 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 |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
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 |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
4 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 |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
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 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
1408 KB |
Output is correct |
6 |
Correct |
8 ms |
1408 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
1280 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
640 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
6 ms |
1280 KB |
Output is correct |
13 |
Correct |
6 ms |
1252 KB |
Output is correct |
14 |
Correct |
4 ms |
484 KB |
Output is correct |
15 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
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 |
Correct |
2 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 |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
7 ms |
1536 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Incorrect |
3 ms |
768 KB |
Output isn't correct |
12 |
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 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Incorrect |
32 ms |
1528 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |