23452023-01-10 21:15:19nmarciBürokrácia (40)cpp11Accepted 40/4067ms27264 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
const ll inf = 1e9;

vector<int> g[100100];
bool done[100100] = {false};
vector<int> sol;

bool dfs(int node){
  done[node] = true;
  if(g[node].size() == 0){
    sol.push_back(node);
    return true;
  }
  bool ok = true;
  for(auto i : g[node]){
    ok &= !dfs(i);
  }
  if(ok) sol.push_back(node);
  return ok;
}

int main()
{
  int n;
  cin >> n;
  for(int i = 1; i <= n; ++i){
    char c;
    cin >> c;
    if(c == 'V'){
      int j;
      cin >> j;
      g[j].push_back(i);
    }
  }
  for(int i = 1; i <= n; ++i){
    if(!done[i]){
      dfs(i);
    }
  }
  sort(begin(sol), end(sol));
  cout << sol.size() << endl;
  for(auto i : sol)
    cout << i << " ";
  return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/04ms6584 KiB
2Accepted1/14ms6816 KiB
3Accepted1/14ms7016 KiB
4Accepted1/14ms7248 KiB
5Accepted1/126ms8692 KiB
6Accepted1/167ms27264 KiB
7Accepted1/157ms14092 KiB
8Accepted2/259ms12940 KiB
9Accepted2/261ms12564 KiB
10Accepted2/263ms12720 KiB
11Accepted2/265ms12192 KiB
12Accepted2/229ms10384 KiB
13Accepted2/229ms10572 KiB
14Accepted2/261ms12316 KiB
15Accepted2/250ms12252 KiB
16Accepted2/228ms10524 KiB
17Accepted2/229ms10512 KiB
18Accepted2/232ms10588 KiB
19Accepted2/226ms9964 KiB
20Accepted2/227ms9972 KiB
21Accepted2/232ms10028 KiB
22Accepted2/261ms16596 KiB
23Accepted4/464ms13760 KiB