https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/01/Codeforces-Round-393-Div-2-8VC-Venture-Cup-2017--Final-Round-Div-2-Edition-problem-C-Pavel-and-barbecue-Solution-in-CC1.png?fit=640%2C360

Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 – Final Round Div. 2 Edition), problem: (C) Pavel and barbecue Solution in C/C++

#include <stdio.h>

#define N 200000

int pp[N], used[N];

void dfs(int i) {
if (used[i])
return;
used[i] = 1;
dfs(pp[i]);
}

int main() {
int n, i, sum, cnt;
static int bb[N];

scanf(“%d”, &n);
for (i = 0; i < n; i++) {
scanf(“%d”, &pp[i]);
pp[i]–;
}
sum = 0;
for (i = 0; i < n; i++) {
scanf(“%d”, &bb[i]);
sum += bb[i];
}
cnt = 0;
for (i = 0; i < n; i++)
if (!used[i]) {
cnt++;
dfs(i);
}
printf(“%d\n”, (cnt == 1 ? 0 : cnt) + (sum % 2 == 0 ? 1 : 0));
return 0;
}

(Visited 77 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: