# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404154 | ly20 | Friend (IOI14_friend) | C++17 | 65 ms | 25448 KiB |
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 "friend.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1123;
int marc[MAXN];
int val[MAXN];
vector <int> grafo[MAXN];
// Find out best sample
int br, pt;
void dfs(int v) {
if(marc[v] == 0) br += val[v];
else pt += val[v];
for(int i = 0; i < grafo[v].size(); i++) {
int viz = grafo[v][i];
if(marc[viz] != -1) {
continue;
}
marc[viz] = 1 - marc[v];
dfs(viz);
}
}
int dp[MAXN][2];
int findSample(int n,int confidence[],int host[],int protocol[]){
int tot = 0;
int mx = 0;
for(int i = 0; i < n; i++) {
marc[i] = -1;
val[i] = confidence[i];
mx = max(mx, val[i]);
}
for(int i = 1; i < n - 1; i++) {
int cur = host[i];
if(protocol[i] == 0 || protocol[i] == 2) {
grafo[i].push_back(cur);
grafo[cur].push_back(i);
}
if(protocol[i] == 1 || protocol[i] == 2) {
for(int j = 0; j < grafo[cur].size(); j++) {
int viz = grafo[cur][j];
grafo[i].push_back(viz);
grafo[viz].push_back(i);
}
}
}
int resp = 0;
for(int i = 0; i < n; i++) {
if(marc[i] == -1) {
br = 0; pt = 0;
marc[i] = 0;
dfs(i);
resp += max(br, pt);
tot += br + pt;
}
}
dp[0][1] = val[0];
dp[0][0] = 0;
for(int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][0] , dp[i - 1][1]);
dp[i][1] = dp[i - 1][0] + val[i];
}
return max(dp[n - 1][0], dp[n - 1][1]);
}
Compilation message (stderr)
# | 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... |