Submission #882562

# Submission time Handle Problem Language Result Execution time Memory
882562 2023-12-03T11:42:42 Z NintsiChkhaidze Tourism (JOI23_tourism) C++17
28 / 100
5000 ms 56284 KB
#include <bits/stdc++.h>
#define s second
#define f first
#define ll long long
#define pb push_back
#define pii pair <int,int>
#define int ll
using namespace std;

const int N = 2e5 + 5,inf = 1e18;

int dp[N],d[25][N],arr[N],fix[N];
int L[N],R[N],ans[N];
vector <int> v[N],qr[N];

void dfs(int x,int par){
	d[0][x] = par;
	dp[x] = dp[par] + 1;
	for (int to: v[x]){
		if (to != par){
			dfs(to,x);
		}
	}
}

int lca(int x,int y){
	if (dp[x] < dp[y]) swap(x,y);
	for (int i = 18; i >= 0; i--)
		if (dp[d[i][x]] >= dp[y]) x = d[i][x];

	if (x == y) return x;

	for (int i = 18; i >= 0; i--)
		if (d[i][x] != d[i][y]) x = d[i][x], y = d[i][y];

	return d[0][x];
}

void markpath(int x,int y,int color){
	int c = lca(x,y);
	while (x != c){
		fix[x] = color;
		x = d[0][x];
	}

	while (y != c){
		fix[y] = color;
		y = d[0][y];
	}

	fix[c] = color;
}
signed main (){
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);

	int n,m,q;
	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);
	}

	dfs(1,1);
	for (int j = 1; j <= 18; j++)
		for (int i = 1; i <= n; i++)
			d[j][i] = d[j - 1][d[j - 1][i]];

	for (int i = 1; i <= m; i++)
		cin >> arr[i];

	for (int i = 1; i <= q; i++){
		cin >> L[i] >> R[i];
		if (L[i] == R[i]) ans[i] = 1;
		else qr[L[i]].pb(i);
	}

	for (int i = 1; i <= n; i++)
		fix[i] = m + 1;
	
	//neli 
	for (int i = m; i >= 1; i--){
		if (i != m) markpath(arr[i],arr[i + 1],i + 1);
		for (int id: qr[i]){
			int r = R[id];
			for (int j = 1; j <= n; j++)
				ans[id] += (fix[j] <= r);
		}
	}

	for (int i = 1; i <= q; i++)	
		cout<<ans[i]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 9 ms 47708 KB Output is correct
3 Correct 8 ms 47788 KB Output is correct
4 Correct 7 ms 47828 KB Output is correct
5 Correct 8 ms 47708 KB Output is correct
6 Correct 8 ms 47708 KB Output is correct
7 Correct 8 ms 47708 KB Output is correct
8 Correct 9 ms 47708 KB Output is correct
9 Correct 8 ms 47708 KB Output is correct
10 Correct 8 ms 47708 KB Output is correct
11 Correct 7 ms 31332 KB Output is correct
12 Correct 7 ms 47780 KB Output is correct
13 Correct 5 ms 33444 KB Output is correct
14 Correct 5 ms 27228 KB Output is correct
15 Correct 8 ms 47768 KB Output is correct
16 Correct 6 ms 31352 KB Output is correct
17 Correct 7 ms 47708 KB Output is correct
18 Correct 8 ms 47708 KB Output is correct
19 Correct 7 ms 47704 KB Output is correct
20 Correct 7 ms 39580 KB Output is correct
21 Correct 7 ms 47708 KB Output is correct
22 Correct 4 ms 23388 KB Output is correct
23 Correct 7 ms 47708 KB Output is correct
24 Correct 6 ms 35452 KB Output is correct
25 Correct 7 ms 47852 KB Output is correct
26 Correct 7 ms 39512 KB Output is correct
27 Correct 7 ms 47704 KB Output is correct
28 Correct 8 ms 47708 KB Output is correct
29 Correct 5 ms 31396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 9 ms 47708 KB Output is correct
3 Correct 8 ms 47788 KB Output is correct
4 Correct 7 ms 47828 KB Output is correct
5 Correct 8 ms 47708 KB Output is correct
6 Correct 8 ms 47708 KB Output is correct
7 Correct 8 ms 47708 KB Output is correct
8 Correct 9 ms 47708 KB Output is correct
9 Correct 8 ms 47708 KB Output is correct
10 Correct 8 ms 47708 KB Output is correct
11 Correct 7 ms 31332 KB Output is correct
12 Correct 7 ms 47780 KB Output is correct
13 Correct 5 ms 33444 KB Output is correct
14 Correct 5 ms 27228 KB Output is correct
15 Correct 8 ms 47768 KB Output is correct
16 Correct 6 ms 31352 KB Output is correct
17 Correct 7 ms 47708 KB Output is correct
18 Correct 8 ms 47708 KB Output is correct
19 Correct 7 ms 47704 KB Output is correct
20 Correct 7 ms 39580 KB Output is correct
21 Correct 7 ms 47708 KB Output is correct
22 Correct 4 ms 23388 KB Output is correct
23 Correct 7 ms 47708 KB Output is correct
24 Correct 6 ms 35452 KB Output is correct
25 Correct 7 ms 47852 KB Output is correct
26 Correct 7 ms 39512 KB Output is correct
27 Correct 7 ms 47704 KB Output is correct
28 Correct 8 ms 47708 KB Output is correct
29 Correct 5 ms 31396 KB Output is correct
30 Correct 11 ms 47784 KB Output is correct
31 Correct 15 ms 47964 KB Output is correct
32 Correct 15 ms 48024 KB Output is correct
33 Correct 14 ms 45920 KB Output is correct
34 Correct 12 ms 47964 KB Output is correct
35 Correct 13 ms 43868 KB Output is correct
36 Correct 14 ms 47964 KB Output is correct
37 Correct 17 ms 47964 KB Output is correct
38 Correct 19 ms 44184 KB Output is correct
39 Correct 17 ms 43864 KB Output is correct
40 Correct 20 ms 47964 KB Output is correct
41 Correct 20 ms 47960 KB Output is correct
42 Correct 15 ms 45916 KB Output is correct
43 Correct 15 ms 47964 KB Output is correct
44 Correct 14 ms 47964 KB Output is correct
45 Correct 13 ms 48036 KB Output is correct
46 Correct 14 ms 47964 KB Output is correct
47 Correct 14 ms 47960 KB Output is correct
48 Correct 14 ms 47964 KB Output is correct
49 Correct 13 ms 47964 KB Output is correct
50 Correct 15 ms 47964 KB Output is correct
51 Correct 13 ms 47964 KB Output is correct
52 Correct 14 ms 48032 KB Output is correct
53 Correct 12 ms 47964 KB Output is correct
54 Correct 12 ms 47964 KB Output is correct
55 Correct 14 ms 47896 KB Output is correct
56 Correct 11 ms 47708 KB Output is correct
57 Correct 9 ms 47964 KB Output is correct
58 Correct 10 ms 47888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47704 KB Output is correct
2 Correct 9 ms 47708 KB Output is correct
3 Correct 9 ms 47708 KB Output is correct
4 Execution timed out 5079 ms 56104 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 167 ms 51292 KB Output is correct
3 Correct 158 ms 51536 KB Output is correct
4 Correct 204 ms 52116 KB Output is correct
5 Correct 151 ms 53844 KB Output is correct
6 Correct 152 ms 53840 KB Output is correct
7 Correct 160 ms 53840 KB Output is correct
8 Correct 166 ms 53844 KB Output is correct
9 Correct 187 ms 53840 KB Output is correct
10 Correct 176 ms 54096 KB Output is correct
11 Correct 225 ms 54096 KB Output is correct
12 Correct 454 ms 54212 KB Output is correct
13 Correct 846 ms 54508 KB Output is correct
14 Correct 1982 ms 55276 KB Output is correct
15 Correct 276 ms 55384 KB Output is correct
16 Correct 841 ms 54512 KB Output is correct
17 Correct 865 ms 54508 KB Output is correct
18 Correct 898 ms 54508 KB Output is correct
19 Correct 1002 ms 53580 KB Output is correct
20 Correct 1041 ms 53580 KB Output is correct
21 Correct 1047 ms 53560 KB Output is correct
22 Correct 928 ms 53572 KB Output is correct
23 Correct 1122 ms 53576 KB Output is correct
24 Correct 892 ms 53560 KB Output is correct
25 Correct 1074 ms 53688 KB Output is correct
26 Correct 933 ms 53604 KB Output is correct
27 Correct 893 ms 53844 KB Output is correct
28 Correct 1022 ms 53592 KB Output is correct
29 Correct 1026 ms 53664 KB Output is correct
30 Correct 1375 ms 53804 KB Output is correct
31 Correct 1717 ms 53996 KB Output is correct
32 Correct 2410 ms 54416 KB Output is correct
33 Correct 3100 ms 55116 KB Output is correct
34 Correct 1278 ms 55284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 8 ms 47828 KB Output is correct
3 Correct 10 ms 47708 KB Output is correct
4 Correct 3524 ms 55120 KB Output is correct
5 Correct 3424 ms 55124 KB Output is correct
6 Execution timed out 5040 ms 56284 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47708 KB Output is correct
2 Correct 9 ms 47708 KB Output is correct
3 Correct 8 ms 47788 KB Output is correct
4 Correct 7 ms 47828 KB Output is correct
5 Correct 8 ms 47708 KB Output is correct
6 Correct 8 ms 47708 KB Output is correct
7 Correct 8 ms 47708 KB Output is correct
8 Correct 9 ms 47708 KB Output is correct
9 Correct 8 ms 47708 KB Output is correct
10 Correct 8 ms 47708 KB Output is correct
11 Correct 7 ms 31332 KB Output is correct
12 Correct 7 ms 47780 KB Output is correct
13 Correct 5 ms 33444 KB Output is correct
14 Correct 5 ms 27228 KB Output is correct
15 Correct 8 ms 47768 KB Output is correct
16 Correct 6 ms 31352 KB Output is correct
17 Correct 7 ms 47708 KB Output is correct
18 Correct 8 ms 47708 KB Output is correct
19 Correct 7 ms 47704 KB Output is correct
20 Correct 7 ms 39580 KB Output is correct
21 Correct 7 ms 47708 KB Output is correct
22 Correct 4 ms 23388 KB Output is correct
23 Correct 7 ms 47708 KB Output is correct
24 Correct 6 ms 35452 KB Output is correct
25 Correct 7 ms 47852 KB Output is correct
26 Correct 7 ms 39512 KB Output is correct
27 Correct 7 ms 47704 KB Output is correct
28 Correct 8 ms 47708 KB Output is correct
29 Correct 5 ms 31396 KB Output is correct
30 Correct 11 ms 47784 KB Output is correct
31 Correct 15 ms 47964 KB Output is correct
32 Correct 15 ms 48024 KB Output is correct
33 Correct 14 ms 45920 KB Output is correct
34 Correct 12 ms 47964 KB Output is correct
35 Correct 13 ms 43868 KB Output is correct
36 Correct 14 ms 47964 KB Output is correct
37 Correct 17 ms 47964 KB Output is correct
38 Correct 19 ms 44184 KB Output is correct
39 Correct 17 ms 43864 KB Output is correct
40 Correct 20 ms 47964 KB Output is correct
41 Correct 20 ms 47960 KB Output is correct
42 Correct 15 ms 45916 KB Output is correct
43 Correct 15 ms 47964 KB Output is correct
44 Correct 14 ms 47964 KB Output is correct
45 Correct 13 ms 48036 KB Output is correct
46 Correct 14 ms 47964 KB Output is correct
47 Correct 14 ms 47960 KB Output is correct
48 Correct 14 ms 47964 KB Output is correct
49 Correct 13 ms 47964 KB Output is correct
50 Correct 15 ms 47964 KB Output is correct
51 Correct 13 ms 47964 KB Output is correct
52 Correct 14 ms 48032 KB Output is correct
53 Correct 12 ms 47964 KB Output is correct
54 Correct 12 ms 47964 KB Output is correct
55 Correct 14 ms 47896 KB Output is correct
56 Correct 11 ms 47708 KB Output is correct
57 Correct 9 ms 47964 KB Output is correct
58 Correct 10 ms 47888 KB Output is correct
59 Correct 6 ms 47704 KB Output is correct
60 Correct 9 ms 47708 KB Output is correct
61 Correct 9 ms 47708 KB Output is correct
62 Execution timed out 5079 ms 56104 KB Time limit exceeded
63 Halted 0 ms 0 KB -