forked from cacophonix/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUREAU.cpp
53 lines (48 loc) · 902 Bytes
/
BUREAU.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
USER: zobayer
TASK: BUREAU
ALGO: ad-hoc
*/
#include <cstdio>
#include <cstring>
using namespace std;
int a[100001];
char ok[100001], buff[16000000], *ptr = buff;
inline int nextint() {
int ret = 0;
while(*ptr < 33) ptr++;
do { ret = ret*10 + *ptr++ - '0'; } while(*ptr > 32);
return ret;
}
inline char *nextstr() {
char *str;
while(*ptr < 33) ptr++;
for(str = ptr; *ptr > 32; ptr++);
return str;
}
int main() {
int test, n, i, f;
fread(buff, 1, 16000000, stdin);
test = nextint();
while(test--) {
n = nextint();
for(i = 1; i <= n; i++) {
if(*nextstr()=='c') a[i] = nextint();
else a[i] = 0;
ok[i] = 1;
}
for(i = n; i; i--)
if(a[i] && ok[i])
ok[a[i]] = 0;
for(f = 0, i = 1; i <= n; i++) f += ok[i];
printf("%d\n", f);
for(i = 1, f = 0; i <= n; i++) {
if(ok[i]) {
if(f++) printf(" ");
printf("%d", i);
}
}
printf("\n");
}
return 0;
}