81652024-01-12 15:18:50anonBürokrácia (40)cpp17Accepted 40/4039ms27080 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
bool solve(ll law, const vector<vector<ll>> &graph, vector<ll> &dp) {
    ll &ans = dp[law];
    if(ans != -1)
        return ans;
    ans = true;
    for(const auto &x : graph[law])
        ans &= !solve(x, graph, dp);
    return ans;
}
int main() {
    FastIO;
    char c;
    ll i, v, N;
    cin >> N;
    vector<vector<ll>> graph(N);
    for(i = 0; i < N; i++) {
        cin >> c;
        if(c == 'R')
            continue;
        cin >> v;
        graph[v - 1].push_back(i);
    }
    vector<ll> ans;
    vector<ll> dp(N, -1);
    for(i = 0; i < N; i++) {
        if(solve(i, graph, dp))
            ans.push_back(i + 1);
    }
    cout << ans.size() << '\n';
    for(const auto &x : ans)
        cout << x << ' ';
    cout << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1976 KiB
2Accepted1/13ms2180 KiB
3Accepted1/13ms2548 KiB
4Accepted1/13ms2812 KiB
5Accepted1/117ms11060 KiB
6Accepted1/137ms26804 KiB
7Accepted1/129ms17732 KiB
8Accepted2/232ms17084 KiB
9Accepted2/235ms17408 KiB
10Accepted2/239ms18124 KiB
11Accepted2/235ms18684 KiB
12Accepted2/217ms17208 KiB
13Accepted2/218ms17632 KiB
14Accepted2/235ms20172 KiB
15Accepted2/229ms20924 KiB
16Accepted2/218ms19432 KiB
17Accepted2/218ms19688 KiB
18Accepted2/218ms20048 KiB
19Accepted2/216ms19860 KiB
20Accepted2/217ms20172 KiB
21Accepted2/217ms20564 KiB
22Accepted2/234ms27080 KiB
23Accepted4/437ms25616 KiB