# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62903 | zadrga | Friend (IOI14_friend) | C++14 | 0 ms | 0 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;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ((int) 1e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 100111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
vector<int> adj[maxn];
int col[maxn];
void DFS(int x, int c){
col[x] = c;
for(int v : adj[x]){
if(!col[v])
DFS(v, 3 - c);
}
}
int findSample(int n, int confidence[], int host[], int protocol[]){
for(int i = 0; i < n; i++)
val[i] = confidence[i];
for(int i = 1; i < n - 1; i++){
int a = host[i];
int b = i;
if(protocol[i] == 0){
adj[a].pb(b);
adj[b].pb(a);
}
if(protocol[i] == 1){
for(int v : adj[a]){
adj[v].pb(b);
adj[b].pb(v);
}
}
}
for(int i = 0; i < n; i++){
if(!col[i])
DFS(i, 1);
}
int ans[3] = {0, 0, 0};
for(int i = 0; i < n; i++)
ans[col[i]] += confidence[i];
return max(ans[1], ans[2]);
}