//I love ManchesterUnited
#include<bits/stdc++.h>
using namespace std;
#define love ManchesterUnited
#define pb push_back
#define FOR(i,a,b) for (int i=(a); i<=(b); i++)
#define FORD(i,b,a) for (int i=(b); i>=(a); i--)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define endl '\n'
const int N = 1005;
int n,q,ans;
vector<int> adj[N];
int pet[N];
vector<int> a,b;
bool vis[N];
int chan[N][N];
void dfs(int u,int par,int type){
vis[u] = 1;
if (pet[u]){
if (pet[u] != type){
chan[par][u] = 1;
chan[u][par] = 1;
ans++;
return;
}
}
for (int v : adj[u]) if (v != par && !vis[v]){
if (chan[v][u]) continue;
dfs(v,u,type);
}
}
int dangerLevel() {
memset(vis,0,sizeof vis);
FOR(i,1,n) {
if (vis[i]) continue;
if (pet[i] == 1 || pet[i] == 2) dfs(i,0,pet[i]);
}
// FOR(i,1,n){
// FOR(j,1,n) cout << chan[i][j] << " ";
// cout << endl;
// }
return ans;
}
void initialize(int N, vector<int> A, vector<int> B){
n = N;
FOR(i,1,n){ adj[i].clear(); pet[i]=0; }
for (int i = 0; i < N-1; i++){
int u = A[i], v = B[i];
adj[u].pb(v);
adj[v].pb(u);
}
}
int cat(int v){
pet[v] = 1;
return dangerLevel();
}
int dog(int v){
pet[v] = 2;
return dangerLevel();
}
int neighbor(int v){
memset(chan, 0, sizeof chan);
ans = 0;
pet[v] = 0;
return dangerLevel();
}
//int32_t main(){
// freopen("test.inp","r",stdin);
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
//
// cin >> n;
// a.resize(n); b.resize(n);
// FOR(i,0,n-2) cin >> a[i];
// FOR(i,0,n-2) cin >> b[i];
//
// initialize(n,a,b);
//
// cin >> q;
// FOR(_,1,q){
// int type,v; cin >> type >> v;
// if (type == 1) cout << cat(v) << endl;
// if (type == 2) cout << dog(v) << endl;
// if (type == 3) cout << neighbor(v) << endl;
// }
//}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |