#include <bits/stdc++.h>
#include "friend.h"
using namespace std;
#define pb push_back
#define sz(s) (int)s.size()
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define all(s) s.begin(), s.end()
const int N = (int)1e5 + 7;
const int smN = (int)1e3 + 7;
vector < int > gr[N];
int has[smN][smN];
int c[N], dp[N], used[N];
void addedge(int a, int b) {
gr[a].pb(b);
gr[b].pb(a);
has[a][b] = has[b][a] = 1;
}
void dfs(int v, int pr) {
used[v] = 1;
for (int to : gr[v]) {
if (to == pr) continue;
assert(used[to] == 0);
dfs(to, v);
if (v != pr) {
dp[pr] = max(dp[pr], dp[to] + c[pr]);
}
dp[v] = max(dp[v], dp[to]);
}
}
int findSample(int n, int confidence[], int host[], int protocol[]){
for (int i = 0; i < n; i++) c[i] = confidence[i];
int ans = 0;
for (int i = 1; i < n; i++) {
if (protocol[i] == 0 || protocol[i] == 2) {
addedge(host[i], i);
}
if (protocol[i] == 1 || protocol[i] == 2) {
for (int to : gr[host[i]]) {
addedge(to, i);
}
}
}
int st = -1;
for (int i = 0; i < n; i++) {
dp[i] = c[i];
if (sz(gr[i]) == 1) st = i;
}
assert(st != -1);
dfs(st, st);
for (int i = 0; i < n; i++) {
assert(used[i] == 1);
}
ans = dp[st];
memset(used, 0, sizeof used);
for (int i = n - 1; i >= 0; i--) {
dp[i] = c[i];
if (sz(gr[i]) == 1) st = i;
}
dfs(st, st);
return max(ans, dp[st]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3064 KB |
Output is correct |
2 |
Correct |
4 ms |
3172 KB |
Output is correct |
3 |
Correct |
4 ms |
3348 KB |
Output is correct |
4 |
Correct |
4 ms |
3348 KB |
Output is correct |
5 |
Correct |
4 ms |
3348 KB |
Output is correct |
6 |
Incorrect |
4 ms |
3348 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
5488 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
6780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6780 KB |
Output is correct |
2 |
Correct |
4 ms |
6780 KB |
Output is correct |
3 |
Correct |
4 ms |
6780 KB |
Output is correct |
4 |
Incorrect |
4 ms |
6780 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
6780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6780 KB |
Output is correct |
2 |
Correct |
4 ms |
6780 KB |
Output is correct |
3 |
Runtime error |
7 ms |
6780 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |