23442023-01-10 21:14:31nmarciBürokrácia (40)cpp11Wrong answer 3/4061ms27360 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);
    }
  }
  cout << sol.size() << endl;
  for(auto i : sol)
    cout << i << " ";
  return 0;
}
SubtaskSumTestVerdictTimeMemory
base3/40
1Wrong answer0/04ms6536 KiB
2Wrong answer0/14ms6856 KiB
3Wrong answer0/14ms7056 KiB
4Wrong answer0/14ms7280 KiB
5Accepted1/124ms8684 KiB
6Wrong answer0/161ms27360 KiB
7Wrong answer0/154ms14344 KiB
8Wrong answer0/256ms13140 KiB
9Wrong answer0/257ms12336 KiB
10Wrong answer0/257ms12224 KiB
11Wrong answer0/259ms11856 KiB
12Wrong answer0/228ms10076 KiB
13Wrong answer0/227ms9984 KiB
14Wrong answer0/256ms11876 KiB
15Wrong answer0/243ms11640 KiB
16Wrong answer0/228ms9996 KiB
17Wrong answer0/228ms10100 KiB
18Wrong answer0/228ms10148 KiB
19Accepted2/225ms9568 KiB
20Wrong answer0/224ms9700 KiB
21Wrong answer0/225ms9944 KiB
22Wrong answer0/259ms16276 KiB
23Wrong answer0/461ms13608 KiB