Submission #889587

# Submission time Handle Problem Language Result Execution time Memory
889587 2023-12-20T03:29:26 Z vjudge1 Tourism (JOI23_tourism) C++17
10 / 100
5000 ms 22704 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;

int binpow (int a, int n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow (a, n-1) * a;
	else {
		int b = binpow (a, n/2);
		return b * b;
	}
}
vector<int>vis(N+1),vis1(N+1);
vector<int>v[N];

void solve(){
	
	int n,q,m,k;
	cin>>n>>m>>q;
	
	for(int i = 1;i<n;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	
	for(int i = 1;i<=m;i++){
		int a;
		cin>>a;
		vis[i] = a;
		vis1[a] = i;
	}
	
	while (q--)
	{
		int l , r;
		cin>>l>>r;
		/*for (int i = 0; i < n + 1; i++){
			dist[i] = mod;
		}*/
		vector<int>dist(n+1);
		queue<pii>q;
		q.push({vis[l],-1});
		dist[vis[l]] = 1;
		vector<int>pred(n+1);
		while(!q.empty()){
			auto [x,pr] = q.front();
			q.pop();
			
			for(auto to:v[x]){
				if(to!=pr){	
					dist[to] = dist[x] + 1;
					pred[to] = x;
					q.push({to,x});
				}
			}
		}
		vector<int>g(n+1);
		for(int i = l + 1;i<=r;i++){
			int y = vis[i];
			while(y!=vis[l]){
				g[y] = 1;
				y = pred[y];
			}
		}
		int cnt = 0;
		for(int i = 1;i<=n;i++)cnt+=g[i];
		cout<<cnt + 1<<"\n";
		
		
	}

	







}

 signed main()
{
//	freopen("seq.in", "r", stdin);
//  freopen("seq.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int tt=1;//cin>>tt;
	while(tt--)solve();

}


Compilation message

tourism.cpp: In function 'void solve()':
tourism.cpp:38:12: warning: unused variable 'k' [-Wunused-variable]
   38 |  int n,q,m,k;
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15964 KB Output is correct
2 Correct 4 ms 15964 KB Output is correct
3 Correct 4 ms 15884 KB Output is correct
4 Correct 6 ms 16112 KB Output is correct
5 Correct 5 ms 16076 KB Output is correct
6 Correct 4 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 5 ms 15964 KB Output is correct
9 Correct 5 ms 15964 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 6 ms 15964 KB Output is correct
12 Correct 6 ms 16148 KB Output is correct
13 Correct 6 ms 15960 KB Output is correct
14 Correct 6 ms 15964 KB Output is correct
15 Correct 10 ms 16068 KB Output is correct
16 Correct 11 ms 15964 KB Output is correct
17 Correct 10 ms 16152 KB Output is correct
18 Correct 8 ms 15964 KB Output is correct
19 Correct 9 ms 15964 KB Output is correct
20 Correct 9 ms 15960 KB Output is correct
21 Correct 6 ms 15964 KB Output is correct
22 Correct 5 ms 15964 KB Output is correct
23 Correct 4 ms 15964 KB Output is correct
24 Correct 5 ms 15964 KB Output is correct
25 Correct 5 ms 15964 KB Output is correct
26 Correct 6 ms 15964 KB Output is correct
27 Correct 4 ms 15964 KB Output is correct
28 Correct 5 ms 15964 KB Output is correct
29 Correct 6 ms 15960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15964 KB Output is correct
2 Correct 4 ms 15964 KB Output is correct
3 Correct 4 ms 15884 KB Output is correct
4 Correct 6 ms 16112 KB Output is correct
5 Correct 5 ms 16076 KB Output is correct
6 Correct 4 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 5 ms 15964 KB Output is correct
9 Correct 5 ms 15964 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 6 ms 15964 KB Output is correct
12 Correct 6 ms 16148 KB Output is correct
13 Correct 6 ms 15960 KB Output is correct
14 Correct 6 ms 15964 KB Output is correct
15 Correct 10 ms 16068 KB Output is correct
16 Correct 11 ms 15964 KB Output is correct
17 Correct 10 ms 16152 KB Output is correct
18 Correct 8 ms 15964 KB Output is correct
19 Correct 9 ms 15964 KB Output is correct
20 Correct 9 ms 15960 KB Output is correct
21 Correct 6 ms 15964 KB Output is correct
22 Correct 5 ms 15964 KB Output is correct
23 Correct 4 ms 15964 KB Output is correct
24 Correct 5 ms 15964 KB Output is correct
25 Correct 5 ms 15964 KB Output is correct
26 Correct 6 ms 15964 KB Output is correct
27 Correct 4 ms 15964 KB Output is correct
28 Correct 5 ms 15964 KB Output is correct
29 Correct 6 ms 15960 KB Output is correct
30 Correct 52 ms 16220 KB Output is correct
31 Correct 55 ms 16216 KB Output is correct
32 Correct 89 ms 16220 KB Output is correct
33 Correct 89 ms 16216 KB Output is correct
34 Correct 85 ms 16240 KB Output is correct
35 Correct 151 ms 16216 KB Output is correct
36 Correct 159 ms 16248 KB Output is correct
37 Correct 160 ms 16216 KB Output is correct
38 Correct 1414 ms 16236 KB Output is correct
39 Correct 1410 ms 16224 KB Output is correct
40 Correct 1421 ms 16480 KB Output is correct
41 Correct 4357 ms 16232 KB Output is correct
42 Correct 3996 ms 16236 KB Output is correct
43 Correct 4208 ms 16236 KB Output is correct
44 Correct 684 ms 16728 KB Output is correct
45 Correct 565 ms 16220 KB Output is correct
46 Correct 638 ms 16216 KB Output is correct
47 Correct 1800 ms 16468 KB Output is correct
48 Correct 1340 ms 16480 KB Output is correct
49 Correct 2050 ms 16476 KB Output is correct
50 Correct 32 ms 16216 KB Output is correct
51 Correct 33 ms 16220 KB Output is correct
52 Correct 32 ms 16296 KB Output is correct
53 Correct 32 ms 16220 KB Output is correct
54 Correct 34 ms 16548 KB Output is correct
55 Correct 33 ms 16220 KB Output is correct
56 Correct 5 ms 15964 KB Output is correct
57 Correct 31 ms 16260 KB Output is correct
58 Correct 49 ms 16216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15960 KB Output is correct
2 Correct 4 ms 15960 KB Output is correct
3 Correct 5 ms 15964 KB Output is correct
4 Execution timed out 5009 ms 19540 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15960 KB Output is correct
2 Correct 1739 ms 19760 KB Output is correct
3 Correct 1986 ms 20112 KB Output is correct
4 Correct 2179 ms 20392 KB Output is correct
5 Correct 48 ms 22352 KB Output is correct
6 Correct 61 ms 22428 KB Output is correct
7 Correct 66 ms 22356 KB Output is correct
8 Correct 124 ms 22552 KB Output is correct
9 Correct 268 ms 22388 KB Output is correct
10 Correct 716 ms 22544 KB Output is correct
11 Correct 2295 ms 22704 KB Output is correct
12 Execution timed out 5038 ms 22428 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15964 KB Output is correct
2 Correct 4 ms 15964 KB Output is correct
3 Correct 5 ms 15964 KB Output is correct
4 Execution timed out 5050 ms 19880 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 15964 KB Output is correct
2 Correct 4 ms 15964 KB Output is correct
3 Correct 4 ms 15884 KB Output is correct
4 Correct 6 ms 16112 KB Output is correct
5 Correct 5 ms 16076 KB Output is correct
6 Correct 4 ms 15964 KB Output is correct
7 Correct 6 ms 15960 KB Output is correct
8 Correct 5 ms 15964 KB Output is correct
9 Correct 5 ms 15964 KB Output is correct
10 Correct 5 ms 15964 KB Output is correct
11 Correct 6 ms 15964 KB Output is correct
12 Correct 6 ms 16148 KB Output is correct
13 Correct 6 ms 15960 KB Output is correct
14 Correct 6 ms 15964 KB Output is correct
15 Correct 10 ms 16068 KB Output is correct
16 Correct 11 ms 15964 KB Output is correct
17 Correct 10 ms 16152 KB Output is correct
18 Correct 8 ms 15964 KB Output is correct
19 Correct 9 ms 15964 KB Output is correct
20 Correct 9 ms 15960 KB Output is correct
21 Correct 6 ms 15964 KB Output is correct
22 Correct 5 ms 15964 KB Output is correct
23 Correct 4 ms 15964 KB Output is correct
24 Correct 5 ms 15964 KB Output is correct
25 Correct 5 ms 15964 KB Output is correct
26 Correct 6 ms 15964 KB Output is correct
27 Correct 4 ms 15964 KB Output is correct
28 Correct 5 ms 15964 KB Output is correct
29 Correct 6 ms 15960 KB Output is correct
30 Correct 52 ms 16220 KB Output is correct
31 Correct 55 ms 16216 KB Output is correct
32 Correct 89 ms 16220 KB Output is correct
33 Correct 89 ms 16216 KB Output is correct
34 Correct 85 ms 16240 KB Output is correct
35 Correct 151 ms 16216 KB Output is correct
36 Correct 159 ms 16248 KB Output is correct
37 Correct 160 ms 16216 KB Output is correct
38 Correct 1414 ms 16236 KB Output is correct
39 Correct 1410 ms 16224 KB Output is correct
40 Correct 1421 ms 16480 KB Output is correct
41 Correct 4357 ms 16232 KB Output is correct
42 Correct 3996 ms 16236 KB Output is correct
43 Correct 4208 ms 16236 KB Output is correct
44 Correct 684 ms 16728 KB Output is correct
45 Correct 565 ms 16220 KB Output is correct
46 Correct 638 ms 16216 KB Output is correct
47 Correct 1800 ms 16468 KB Output is correct
48 Correct 1340 ms 16480 KB Output is correct
49 Correct 2050 ms 16476 KB Output is correct
50 Correct 32 ms 16216 KB Output is correct
51 Correct 33 ms 16220 KB Output is correct
52 Correct 32 ms 16296 KB Output is correct
53 Correct 32 ms 16220 KB Output is correct
54 Correct 34 ms 16548 KB Output is correct
55 Correct 33 ms 16220 KB Output is correct
56 Correct 5 ms 15964 KB Output is correct
57 Correct 31 ms 16260 KB Output is correct
58 Correct 49 ms 16216 KB Output is correct
59 Correct 4 ms 15960 KB Output is correct
60 Correct 4 ms 15960 KB Output is correct
61 Correct 5 ms 15964 KB Output is correct
62 Execution timed out 5009 ms 19540 KB Time limit exceeded
63 Halted 0 ms 0 KB -