Submission #1184804

#TimeUsernameProblemLanguageResultExecution timeMemory
1184804windowwifeSeptember (APIO24_september)C++20
100 / 100
101 ms32192 KiB
#ifndef rtgsp
#include "september.h"
#endif // rtgsp

#include<bits/stdc++.h>
#define ll long long
#define task ""
using namespace std;
const int maxn = 1e6 + 4;
int n, m, res, cnt[maxn], appear, fallen;
bool visited[maxn];
vector<int> adj[maxn];
void dfs (int u)
{
    if (visited[u]) return;
    visited[u] = true;
    fallen++;
    for (int v : adj[u])
        dfs(v);
}
int solve (int N, int M, vector<int> F, vector<vector<int>> S)
{
    n = N; m = M;
    appear = fallen = 0; res = 0;
    for (int i = 0; i < n; i++)
    {
        visited[i] = false;
        adj[i].clear();
        cnt[i] = 0;
    }
    for (int i = 1; i < n; i++)
        adj[F[i]].push_back(i);
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (++cnt[S[j][i]] == m) appear++;
            dfs(S[j][i]);
        }
        if (appear == fallen) res++;
    }
    return res;
}

#ifdef rtgsp
int main ()
{
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << solve(3, 1, {-1, 0, 0}, {{1, 2}}) << '\n';
    cout << solve(5, 2, {-1, 0, 0, 1, 1}, {{1, 2, 3, 4}, {4, 1, 2, 3}}) << '\n';
}
#endif // rtgsp
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...