# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
889727 |
2023-12-20T06:20:30 Z |
vjudge1 |
Tourism (JOI23_tourism) |
C++17 |
|
5000 ms |
5980 KB |
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
const int N = 1e5 + 1;
vector<int> g[N];
int huy1[N],huy2[N];
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m,q;
cin >> n >> m >> q;
for(int i = 0;i < n - 1;i++){
int a,b;
cin >> a >> b;
g[a].pb(b);
g[b].pb(a);
}
for(int i = 1;i <= m;i++){
int a;
cin >> a;
huy1[i] = a;
huy2[a] = i;
}
if(n <= 2000 && m <= 2000 && q <= 2000){
for(int i = 0;i < q;i++){
int l,r;
cin >> l >> r;
vector<int> dis(n + 1);
queue<pair<int,int>> q;
q.push({huy1[l],-1});
vector<int> pr(n + 1);
while(!q.empty()){
auto [v,p] = q.front();q.pop();
for(auto u : g[v]){
if(u != p){
dis[u] = dis[v] + 1;
pr[u] = v;
q.push({u,v});
}
}
}
vector<int> huy3(n + 1);
for(int i = l + 1;i <= r;i++){
int huy4 = huy1[i];
while(huy4 != huy1[l]){
huy3[huy4] = 1;
huy4 = pr[huy4];
}
}
int cnt = 0;
for(int i = 1;i <= n;i++){
cnt += huy3[i];
}
cout << cnt + 1 << "\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3416 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
4 ms |
3420 KB |
Output is correct |
13 |
Correct |
4 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3420 KB |
Output is correct |
15 |
Correct |
8 ms |
3420 KB |
Output is correct |
16 |
Correct |
8 ms |
3416 KB |
Output is correct |
17 |
Correct |
8 ms |
3420 KB |
Output is correct |
18 |
Correct |
5 ms |
3420 KB |
Output is correct |
19 |
Correct |
6 ms |
3420 KB |
Output is correct |
20 |
Correct |
7 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3416 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3320 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3420 KB |
Output is correct |
27 |
Correct |
1 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3416 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
4 ms |
3420 KB |
Output is correct |
13 |
Correct |
4 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3420 KB |
Output is correct |
15 |
Correct |
8 ms |
3420 KB |
Output is correct |
16 |
Correct |
8 ms |
3416 KB |
Output is correct |
17 |
Correct |
8 ms |
3420 KB |
Output is correct |
18 |
Correct |
5 ms |
3420 KB |
Output is correct |
19 |
Correct |
6 ms |
3420 KB |
Output is correct |
20 |
Correct |
7 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3416 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3320 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3420 KB |
Output is correct |
27 |
Correct |
1 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
46 ms |
3420 KB |
Output is correct |
31 |
Correct |
65 ms |
3464 KB |
Output is correct |
32 |
Correct |
102 ms |
3496 KB |
Output is correct |
33 |
Correct |
98 ms |
3420 KB |
Output is correct |
34 |
Correct |
97 ms |
3516 KB |
Output is correct |
35 |
Correct |
177 ms |
3420 KB |
Output is correct |
36 |
Correct |
191 ms |
3752 KB |
Output is correct |
37 |
Correct |
186 ms |
3420 KB |
Output is correct |
38 |
Correct |
1669 ms |
3680 KB |
Output is correct |
39 |
Correct |
1685 ms |
3664 KB |
Output is correct |
40 |
Correct |
1673 ms |
3492 KB |
Output is correct |
41 |
Execution timed out |
5042 ms |
3672 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3160 KB |
Output is correct |
3 |
Correct |
3 ms |
3420 KB |
Output is correct |
4 |
Incorrect |
16 ms |
5980 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Incorrect |
15 ms |
5164 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
3 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
16 ms |
5212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3416 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
3 ms |
3420 KB |
Output is correct |
11 |
Correct |
3 ms |
3420 KB |
Output is correct |
12 |
Correct |
4 ms |
3420 KB |
Output is correct |
13 |
Correct |
4 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3420 KB |
Output is correct |
15 |
Correct |
8 ms |
3420 KB |
Output is correct |
16 |
Correct |
8 ms |
3416 KB |
Output is correct |
17 |
Correct |
8 ms |
3420 KB |
Output is correct |
18 |
Correct |
5 ms |
3420 KB |
Output is correct |
19 |
Correct |
6 ms |
3420 KB |
Output is correct |
20 |
Correct |
7 ms |
3420 KB |
Output is correct |
21 |
Correct |
2 ms |
3416 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3320 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
2 ms |
3420 KB |
Output is correct |
27 |
Correct |
1 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3420 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
46 ms |
3420 KB |
Output is correct |
31 |
Correct |
65 ms |
3464 KB |
Output is correct |
32 |
Correct |
102 ms |
3496 KB |
Output is correct |
33 |
Correct |
98 ms |
3420 KB |
Output is correct |
34 |
Correct |
97 ms |
3516 KB |
Output is correct |
35 |
Correct |
177 ms |
3420 KB |
Output is correct |
36 |
Correct |
191 ms |
3752 KB |
Output is correct |
37 |
Correct |
186 ms |
3420 KB |
Output is correct |
38 |
Correct |
1669 ms |
3680 KB |
Output is correct |
39 |
Correct |
1685 ms |
3664 KB |
Output is correct |
40 |
Correct |
1673 ms |
3492 KB |
Output is correct |
41 |
Execution timed out |
5042 ms |
3672 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |