# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087353 |
2024-09-12T14:23:06 Z |
coldbr3w |
Tourism (JOI23_tourism) |
C++17 |
|
5000 ms |
32340 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 3e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m,q,timer=0;
vector<ll>adj[N];
ll up[N][20], d[N], tin[N], a[N];
void pre_dfs(ll u, ll par){
tin[u] = ++timer;
for(auto v : adj[u]){
if(v == par) continue;
up[v][0] = u;
for(int i = 1; i <= 19;i++) up[v][i] = up[up[v][i-1]][i-1];
d[v] = d[u] + 1;
pre_dfs(v, u);
}
}
ll lca(ll u, ll v){
if(d[u] != d[v]){
if(d[u] < d[v]) swap(u, v);
ll k = d[u] - d[v];
for(int i = 19; i >= 0;i--) if(k & (1 << i)) u = up[u][i];
}
if(u == v) return u;
for(int i = 19; i >= 0;i--) if(up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
return up[u][0];
}
ll dist(ll u, ll v){return d[u] + d[v] - 2 * d[lca(u, v)];}
void to_thic_cau(){
cin >> n >> m >> q;
for(int i = 1; i <= n - 1;i++){
ll u,v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
pre_dfs(1, 0);
for(int i = 1; i <= m;i++) cin >> a[i];
while(q--){
ll l,r; cin >> l >> r;
vector<ll>v;
for(int i = l; i <= r;i++) v.pb(a[i]);
sort(all(v), [&](const ll &a, const ll&b){
return tin[a] < tin[b];
});
ll res = 0;
for(int i = 1; i < v.size();i++) res += dist(v[i], v[i-1]);
res += dist(v[0], v.back());
res /= 2;
cout << res + 1 << '\n';
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
Compilation message
tourism.cpp: In function 'void to_thic_cau()':
tourism.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = 1; i < v.size();i++) res += dist(v[i], v[i-1]);
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7512 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7536 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
5 ms |
7580 KB |
Output is correct |
7 |
Correct |
4 ms |
7512 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
5 ms |
7512 KB |
Output is correct |
10 |
Correct |
5 ms |
7768 KB |
Output is correct |
11 |
Correct |
5 ms |
7516 KB |
Output is correct |
12 |
Correct |
12 ms |
7516 KB |
Output is correct |
13 |
Correct |
9 ms |
7516 KB |
Output is correct |
14 |
Correct |
9 ms |
7624 KB |
Output is correct |
15 |
Correct |
5 ms |
7516 KB |
Output is correct |
16 |
Correct |
5 ms |
7516 KB |
Output is correct |
17 |
Correct |
5 ms |
7628 KB |
Output is correct |
18 |
Correct |
5 ms |
7516 KB |
Output is correct |
19 |
Correct |
5 ms |
7512 KB |
Output is correct |
20 |
Correct |
5 ms |
7512 KB |
Output is correct |
21 |
Correct |
5 ms |
7516 KB |
Output is correct |
22 |
Correct |
5 ms |
7480 KB |
Output is correct |
23 |
Correct |
5 ms |
7516 KB |
Output is correct |
24 |
Correct |
5 ms |
7516 KB |
Output is correct |
25 |
Correct |
5 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7516 KB |
Output is correct |
27 |
Correct |
3 ms |
7516 KB |
Output is correct |
28 |
Correct |
3 ms |
7516 KB |
Output is correct |
29 |
Correct |
3 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7512 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7536 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
5 ms |
7580 KB |
Output is correct |
7 |
Correct |
4 ms |
7512 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
5 ms |
7512 KB |
Output is correct |
10 |
Correct |
5 ms |
7768 KB |
Output is correct |
11 |
Correct |
5 ms |
7516 KB |
Output is correct |
12 |
Correct |
12 ms |
7516 KB |
Output is correct |
13 |
Correct |
9 ms |
7516 KB |
Output is correct |
14 |
Correct |
9 ms |
7624 KB |
Output is correct |
15 |
Correct |
5 ms |
7516 KB |
Output is correct |
16 |
Correct |
5 ms |
7516 KB |
Output is correct |
17 |
Correct |
5 ms |
7628 KB |
Output is correct |
18 |
Correct |
5 ms |
7516 KB |
Output is correct |
19 |
Correct |
5 ms |
7512 KB |
Output is correct |
20 |
Correct |
5 ms |
7512 KB |
Output is correct |
21 |
Correct |
5 ms |
7516 KB |
Output is correct |
22 |
Correct |
5 ms |
7480 KB |
Output is correct |
23 |
Correct |
5 ms |
7516 KB |
Output is correct |
24 |
Correct |
5 ms |
7516 KB |
Output is correct |
25 |
Correct |
5 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7516 KB |
Output is correct |
27 |
Correct |
3 ms |
7516 KB |
Output is correct |
28 |
Correct |
3 ms |
7516 KB |
Output is correct |
29 |
Correct |
3 ms |
7516 KB |
Output is correct |
30 |
Correct |
63 ms |
7924 KB |
Output is correct |
31 |
Correct |
91 ms |
7772 KB |
Output is correct |
32 |
Correct |
126 ms |
8024 KB |
Output is correct |
33 |
Correct |
125 ms |
8052 KB |
Output is correct |
34 |
Correct |
123 ms |
8028 KB |
Output is correct |
35 |
Correct |
342 ms |
8024 KB |
Output is correct |
36 |
Correct |
330 ms |
8024 KB |
Output is correct |
37 |
Correct |
341 ms |
8024 KB |
Output is correct |
38 |
Correct |
91 ms |
8120 KB |
Output is correct |
39 |
Correct |
90 ms |
8028 KB |
Output is correct |
40 |
Correct |
90 ms |
8112 KB |
Output is correct |
41 |
Correct |
260 ms |
8024 KB |
Output is correct |
42 |
Correct |
265 ms |
8028 KB |
Output is correct |
43 |
Correct |
266 ms |
8028 KB |
Output is correct |
44 |
Correct |
91 ms |
8056 KB |
Output is correct |
45 |
Correct |
95 ms |
8028 KB |
Output is correct |
46 |
Correct |
94 ms |
8028 KB |
Output is correct |
47 |
Correct |
271 ms |
8028 KB |
Output is correct |
48 |
Correct |
264 ms |
8028 KB |
Output is correct |
49 |
Correct |
262 ms |
8028 KB |
Output is correct |
50 |
Correct |
120 ms |
8024 KB |
Output is correct |
51 |
Correct |
116 ms |
8028 KB |
Output is correct |
52 |
Correct |
115 ms |
8036 KB |
Output is correct |
53 |
Correct |
113 ms |
8028 KB |
Output is correct |
54 |
Correct |
121 ms |
8028 KB |
Output is correct |
55 |
Correct |
113 ms |
8040 KB |
Output is correct |
56 |
Correct |
17 ms |
7516 KB |
Output is correct |
57 |
Correct |
4 ms |
7768 KB |
Output is correct |
58 |
Correct |
4 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7536 KB |
Output is correct |
3 |
Correct |
17 ms |
7516 KB |
Output is correct |
4 |
Execution timed out |
5037 ms |
25976 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
32 ms |
20372 KB |
Output is correct |
3 |
Correct |
44 ms |
21836 KB |
Output is correct |
4 |
Correct |
42 ms |
23396 KB |
Output is correct |
5 |
Correct |
61 ms |
31944 KB |
Output is correct |
6 |
Correct |
60 ms |
31680 KB |
Output is correct |
7 |
Correct |
61 ms |
31188 KB |
Output is correct |
8 |
Correct |
63 ms |
30800 KB |
Output is correct |
9 |
Correct |
66 ms |
30824 KB |
Output is correct |
10 |
Correct |
66 ms |
30800 KB |
Output is correct |
11 |
Correct |
77 ms |
30816 KB |
Output is correct |
12 |
Correct |
64 ms |
30964 KB |
Output is correct |
13 |
Correct |
65 ms |
31060 KB |
Output is correct |
14 |
Correct |
64 ms |
31404 KB |
Output is correct |
15 |
Correct |
61 ms |
32340 KB |
Output is correct |
16 |
Correct |
67 ms |
31696 KB |
Output is correct |
17 |
Correct |
63 ms |
31696 KB |
Output is correct |
18 |
Correct |
61 ms |
31692 KB |
Output is correct |
19 |
Correct |
54 ms |
31696 KB |
Output is correct |
20 |
Correct |
58 ms |
31304 KB |
Output is correct |
21 |
Correct |
58 ms |
30804 KB |
Output is correct |
22 |
Correct |
62 ms |
30720 KB |
Output is correct |
23 |
Correct |
66 ms |
30608 KB |
Output is correct |
24 |
Correct |
59 ms |
30548 KB |
Output is correct |
25 |
Correct |
66 ms |
30404 KB |
Output is correct |
26 |
Correct |
67 ms |
30544 KB |
Output is correct |
27 |
Correct |
80 ms |
30656 KB |
Output is correct |
28 |
Correct |
67 ms |
30368 KB |
Output is correct |
29 |
Correct |
74 ms |
30464 KB |
Output is correct |
30 |
Correct |
71 ms |
30548 KB |
Output is correct |
31 |
Correct |
73 ms |
30544 KB |
Output is correct |
32 |
Correct |
84 ms |
30804 KB |
Output is correct |
33 |
Correct |
73 ms |
31060 KB |
Output is correct |
34 |
Correct |
60 ms |
31828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7768 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
17 ms |
7600 KB |
Output is correct |
4 |
Execution timed out |
5096 ms |
23136 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7512 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7536 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
5 ms |
7580 KB |
Output is correct |
7 |
Correct |
4 ms |
7512 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
5 ms |
7512 KB |
Output is correct |
10 |
Correct |
5 ms |
7768 KB |
Output is correct |
11 |
Correct |
5 ms |
7516 KB |
Output is correct |
12 |
Correct |
12 ms |
7516 KB |
Output is correct |
13 |
Correct |
9 ms |
7516 KB |
Output is correct |
14 |
Correct |
9 ms |
7624 KB |
Output is correct |
15 |
Correct |
5 ms |
7516 KB |
Output is correct |
16 |
Correct |
5 ms |
7516 KB |
Output is correct |
17 |
Correct |
5 ms |
7628 KB |
Output is correct |
18 |
Correct |
5 ms |
7516 KB |
Output is correct |
19 |
Correct |
5 ms |
7512 KB |
Output is correct |
20 |
Correct |
5 ms |
7512 KB |
Output is correct |
21 |
Correct |
5 ms |
7516 KB |
Output is correct |
22 |
Correct |
5 ms |
7480 KB |
Output is correct |
23 |
Correct |
5 ms |
7516 KB |
Output is correct |
24 |
Correct |
5 ms |
7516 KB |
Output is correct |
25 |
Correct |
5 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7516 KB |
Output is correct |
27 |
Correct |
3 ms |
7516 KB |
Output is correct |
28 |
Correct |
3 ms |
7516 KB |
Output is correct |
29 |
Correct |
3 ms |
7516 KB |
Output is correct |
30 |
Correct |
63 ms |
7924 KB |
Output is correct |
31 |
Correct |
91 ms |
7772 KB |
Output is correct |
32 |
Correct |
126 ms |
8024 KB |
Output is correct |
33 |
Correct |
125 ms |
8052 KB |
Output is correct |
34 |
Correct |
123 ms |
8028 KB |
Output is correct |
35 |
Correct |
342 ms |
8024 KB |
Output is correct |
36 |
Correct |
330 ms |
8024 KB |
Output is correct |
37 |
Correct |
341 ms |
8024 KB |
Output is correct |
38 |
Correct |
91 ms |
8120 KB |
Output is correct |
39 |
Correct |
90 ms |
8028 KB |
Output is correct |
40 |
Correct |
90 ms |
8112 KB |
Output is correct |
41 |
Correct |
260 ms |
8024 KB |
Output is correct |
42 |
Correct |
265 ms |
8028 KB |
Output is correct |
43 |
Correct |
266 ms |
8028 KB |
Output is correct |
44 |
Correct |
91 ms |
8056 KB |
Output is correct |
45 |
Correct |
95 ms |
8028 KB |
Output is correct |
46 |
Correct |
94 ms |
8028 KB |
Output is correct |
47 |
Correct |
271 ms |
8028 KB |
Output is correct |
48 |
Correct |
264 ms |
8028 KB |
Output is correct |
49 |
Correct |
262 ms |
8028 KB |
Output is correct |
50 |
Correct |
120 ms |
8024 KB |
Output is correct |
51 |
Correct |
116 ms |
8028 KB |
Output is correct |
52 |
Correct |
115 ms |
8036 KB |
Output is correct |
53 |
Correct |
113 ms |
8028 KB |
Output is correct |
54 |
Correct |
121 ms |
8028 KB |
Output is correct |
55 |
Correct |
113 ms |
8040 KB |
Output is correct |
56 |
Correct |
17 ms |
7516 KB |
Output is correct |
57 |
Correct |
4 ms |
7768 KB |
Output is correct |
58 |
Correct |
4 ms |
7772 KB |
Output is correct |
59 |
Correct |
3 ms |
7516 KB |
Output is correct |
60 |
Correct |
4 ms |
7536 KB |
Output is correct |
61 |
Correct |
17 ms |
7516 KB |
Output is correct |
62 |
Execution timed out |
5037 ms |
25976 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |