# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
998967 | THXuan | September (APIO24_september) | C++17 | 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 <bits/stdc++.h>
#include "september.h"
#include <bits/stdc++.h>
#define INF 1e18
using namespace std;
typedef long long ll;
vector<int>adj[800005];
bool visited[800005];
int v = 0;
void dfs(int s, int e){
if(visited[s]) return;
visited[s] = true;
++v;
for(auto u : adj[s]){
if(u==e) continue;
dfs(u, s);
}
}
int solve(int N, int M, vector<int> F, vector<vector<int>>S) {
for(int i =1; i < N;i++){
adj[i].push_back(F[i]);
adj[F[i]].push_back(i);
}
int ans = 0;
for(int i =0;i<N-1;i++){
for(int j =0;j<M;j++)dfs(S[j][i]);
ans += !--v;
}
return ans;
}