QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#365239 | #5494. 软件包管理器 | stegatxins0 | 0 | 0ms | 0kb | C++20 | 1.0kb | 2024-03-24 22:21:09 | 2024-03-24 22:21:09 |
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
int n;
int adj[maxn], visited[maxn],ans;
vector<int> radj[maxn];
void dfs(int k){
visited[k] = 1;
ans++;
if(k == 0)return;
if(!visited[adj[k]])dfs(adj[k]);
}
void rdfs(int k){
visited[k] = 0;
ans++;
for(auto x:radj[k]){
//cerr << x << " ";
if(visited[x])rdfs(x);
}
//cerr << endl;
}
int main(){
freopen("manager.in", "r", stdin);
freopen("manager.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i=1;i<=n-1;i++){
cin >> adj[i];
radj[adj[i]].push_back(i);
}
memset(visited,0,sizeof(visited));
int q, node; cin >> q;
string comm;
while(q--){
cin >> comm >> node;
ans=0;
if(comm == "install"){
if(!visited[node])dfs(node);
}else if(comm == "uninstall"){
if(visited[node])rdfs(node);
}
cout << ans << "\n";
}
}
详细
Test #1:
score: 0
Dangerous Syscalls
input:
5000 1197 1612 491 3490 3733 0 0 3931 3369 4435 321 1353 2697 938 3328 4392 3119 4473 0 2503 1082 3880 4507 2372 4977 3341 4390 3183 1719 3241 3443 3832 2394 0 1666 609 2625 4805 4406 4721 89 3020 0 706 74 2003 729 3221 0 0 2882 1522 4880 1794 4672 3137 2963 0 1299 3535 2022 2284 199 0 1056 0 0 420 ...
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
5000 1197 1612 491 3490 3733 0 0 3931 3369 4435 321 1353 2697 938 3328 4392 3119 4473 0 2503 1082 3880 4507 2372 4977 3341 4390 3183 1719 3241 3443 3832 2394 0 1666 609 2625 4805 4406 4721 89 3020 0 706 74 2003 729 3221 0 0 2882 1522 4880 1794 4672 3137 2963 0 1299 3535 2022 2284 199 0 1056 0 0 420 ...
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
100000 0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
100000 0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
100000 0 1 0 0 4 0 5 7 6 3 1 8 10 8 14 8 16 12 17 14 9 8 21 4 12 22 2 5 24 27 7 25 14 8 10 26 3 35 21 23 23 7 29 22 15 20 45 21 11 49 12 6 50 5 40 33 35 54 2 27 1 48 59 15 45 33 57 61 33 6 69 14 65 37 14 21 13 20 46 12 16 12 61 26 68 55 69 45 49 55 61 71 31 12 30 74 12 23 95 37 51 93 5 103 44 73 101...
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
100000 0 1 2 1 2 3 2 4 3 4 2 11 12 6 8 7 3 8 12 18 2 20 7 0 13 23 14 22 26 3 17 31 2 16 18 25 23 30 16 25 7 33 21 0 18 2 27 45 36 16 23 29 31 7 39 53 19 12 50 53 58 17 40 32 18 46 54 10 4 25 64 64 20 25 22 66 4 68 30 56 17 74 19 81 5 58 25 79 75 47 55 38 35 69 92 71 30 31 98 78 76 80 10 96 63 42 31 ...
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
100000 0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
100000 0 0 0 1 2 4 1 7 3 5 9 4 7 9 6 12 2 7 15 15 1 7 18 18 2 18 11 25 13 10 13 21 23 9 16 0 3 25 38 15 31 30 14 34 41 45 35 7 39 5 12 21 45 22 35 14 26 27 52 29 20 50 33 24 0 51 31 6 68 57 39 12 54 21 58 21 71 46 37 27 28 6 39 30 34 16 67 45 76 87 37 25 84 35 46 62 85 13 52 76 53 98 45 50 35 8 64 1...
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #11:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #12:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #13:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #14:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #15:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #16:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #17:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #18:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #19:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...
output:
result:
Test #20:
score: 0
Dangerous Syscalls
input:
100000 67900 38650 71400 4599 90457 91976 56382 60188 88280 94727 0 91149 39722 79239 53412 19144 44540 58803 43574 28515 66477 15585 98202 31397 48655 81036 69170 59687 69954 99538 3170 14923 53437 96022 84960 71972 24205 46764 47685 50572 84521 54475 63602 50837 24017 0 84383 67721 82796 21296 975...