#include "catdog.h"
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
int n;
int tot;
vector<int> adj[100010];
int type[100010];
bool visited[100010];
void dfs(int node, int t){
visited[node] = true;
for(unsigned int i=0;i<adj[node].size();i++){
int viz = adj[node][i];
if(!visited[viz]&&type[viz]!=((t%2)+1)){
dfs(viz, t);
}
}
}
int find_components(){
tot = 0;
memset(visited, false, sizeof visited);
for(int i=1;i<=n;i++){
if(!visited[i]){
dfs(i, type[i]);
tot++;
}
}
return tot-1;
}
void initialize(int N, vector<int> A, vector<int> B) {
n = N;
for(int i=0;i<n-1;i++){
adj[A[i]].push_back(B[i]); adj[B[i]].push_back(A[i]);
}
memset(type, 0, sizeof type);
}
int cat(int v) {
type[v] = 1;
return find_components();
}
int dog(int v) {
type[v] = 2;
return find_components();
}
int neighbor(int v) {
type[v] = 0;
return find_components();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |