답안 #950086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950086 2024-03-20T05:09:07 Z Abito Tourism (JOI23_tourism) C++17
28 / 100
5000 ms 72924 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=1e5+5;
int n,par[N],b[N],m,q,euler[2*N],c,dis[N],f[N],lg[2*N],vis[N];
vector<int> adj[N];
pair<int,int> st[20][2*N];
void dfs(int x,int p){
    par[x]=p;
    euler[++c]=x;
    f[x]=c;
    dis[x]=dis[p]+1;
    for (auto u:adj[x]){
        if (u==p) continue;
        dfs(u,x);
        euler[++c]=x;
    }
    return;
}
void build(){
    for (int i=1;i<=c;i++) st[0][i]={dis[euler[i]],euler[i]};
    for (int i=1;i<20;i++){
        for (int j=1;j+(1<<i)<=c+1;j++){
            st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
        }
    }return;
}
int query(int l,int r){
    if (l>r) swap(l,r);
    int i=lg[r-l+1];
    return min(st[i][l],st[i][r-(1<<i)+1]).S;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    for (int i=2;i<2*N;i++) lg[i]=lg[i/2]+1;
    cin>>n>>m>>q;
    for (int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1,0);
    build();
    for (int i=1;i<=m;i++) cin>>b[i];
    while (q--){
        c++;
        int l,r;
        cin>>l>>r;
        int lca=b[l],ans=0;
        for (int i=l;i<=r;i++){
            lca=query(f[lca],f[b[i]]);
        }
        //cout<<lca<<endl;
        for (int i=l;i<=r;i++){
            int x=b[i];
            while (dis[x]>=dis[lca] && c!=vis[x]){
                ans++;
                vis[x]=c;
                x=par[x];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14832 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 8 ms 24924 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 4 ms 24920 KB Output is correct
7 Correct 4 ms 24920 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 4 ms 26972 KB Output is correct
10 Correct 5 ms 27188 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 5 ms 26972 KB Output is correct
13 Correct 5 ms 26972 KB Output is correct
14 Correct 5 ms 26972 KB Output is correct
15 Correct 5 ms 26972 KB Output is correct
16 Correct 4 ms 26972 KB Output is correct
17 Correct 5 ms 26972 KB Output is correct
18 Correct 4 ms 26972 KB Output is correct
19 Correct 4 ms 26972 KB Output is correct
20 Correct 5 ms 27064 KB Output is correct
21 Correct 4 ms 26968 KB Output is correct
22 Correct 4 ms 26972 KB Output is correct
23 Correct 4 ms 26972 KB Output is correct
24 Correct 5 ms 26972 KB Output is correct
25 Correct 4 ms 26972 KB Output is correct
26 Correct 4 ms 26968 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 4 ms 26972 KB Output is correct
29 Correct 5 ms 27100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14832 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 8 ms 24924 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 4 ms 24920 KB Output is correct
7 Correct 4 ms 24920 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 4 ms 26972 KB Output is correct
10 Correct 5 ms 27188 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 5 ms 26972 KB Output is correct
13 Correct 5 ms 26972 KB Output is correct
14 Correct 5 ms 26972 KB Output is correct
15 Correct 5 ms 26972 KB Output is correct
16 Correct 4 ms 26972 KB Output is correct
17 Correct 5 ms 26972 KB Output is correct
18 Correct 4 ms 26972 KB Output is correct
19 Correct 4 ms 26972 KB Output is correct
20 Correct 5 ms 27064 KB Output is correct
21 Correct 4 ms 26968 KB Output is correct
22 Correct 4 ms 26972 KB Output is correct
23 Correct 4 ms 26972 KB Output is correct
24 Correct 5 ms 26972 KB Output is correct
25 Correct 4 ms 26972 KB Output is correct
26 Correct 4 ms 26968 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 4 ms 26972 KB Output is correct
29 Correct 5 ms 27100 KB Output is correct
30 Correct 20 ms 31324 KB Output is correct
31 Correct 22 ms 31320 KB Output is correct
32 Correct 32 ms 31320 KB Output is correct
33 Correct 32 ms 31324 KB Output is correct
34 Correct 32 ms 31440 KB Output is correct
35 Correct 53 ms 31324 KB Output is correct
36 Correct 54 ms 31428 KB Output is correct
37 Correct 52 ms 31416 KB Output is correct
38 Correct 33 ms 31320 KB Output is correct
39 Correct 34 ms 31324 KB Output is correct
40 Correct 32 ms 31320 KB Output is correct
41 Correct 57 ms 31320 KB Output is correct
42 Correct 56 ms 31324 KB Output is correct
43 Correct 64 ms 31460 KB Output is correct
44 Correct 31 ms 31320 KB Output is correct
45 Correct 34 ms 31324 KB Output is correct
46 Correct 32 ms 31324 KB Output is correct
47 Correct 55 ms 31324 KB Output is correct
48 Correct 56 ms 31676 KB Output is correct
49 Correct 55 ms 31324 KB Output is correct
50 Correct 28 ms 31436 KB Output is correct
51 Correct 27 ms 31324 KB Output is correct
52 Correct 27 ms 31324 KB Output is correct
53 Correct 26 ms 31444 KB Output is correct
54 Correct 26 ms 31324 KB Output is correct
55 Correct 27 ms 31320 KB Output is correct
56 Correct 16 ms 8540 KB Output is correct
57 Correct 5 ms 31324 KB Output is correct
58 Correct 6 ms 31324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 16 ms 8540 KB Output is correct
4 Execution timed out 5032 ms 66024 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 36 ms 64348 KB Output is correct
3 Correct 44 ms 64876 KB Output is correct
4 Correct 43 ms 67412 KB Output is correct
5 Correct 58 ms 71860 KB Output is correct
6 Correct 54 ms 71688 KB Output is correct
7 Correct 55 ms 71764 KB Output is correct
8 Correct 68 ms 71624 KB Output is correct
9 Correct 58 ms 71760 KB Output is correct
10 Correct 63 ms 71756 KB Output is correct
11 Correct 60 ms 71788 KB Output is correct
12 Correct 62 ms 71764 KB Output is correct
13 Correct 65 ms 71900 KB Output is correct
14 Correct 72 ms 72176 KB Output is correct
15 Correct 72 ms 72924 KB Output is correct
16 Correct 63 ms 71764 KB Output is correct
17 Correct 63 ms 71912 KB Output is correct
18 Correct 66 ms 71764 KB Output is correct
19 Correct 56 ms 71332 KB Output is correct
20 Correct 62 ms 71264 KB Output is correct
21 Correct 54 ms 71132 KB Output is correct
22 Correct 60 ms 71256 KB Output is correct
23 Correct 76 ms 71256 KB Output is correct
24 Correct 102 ms 71256 KB Output is correct
25 Correct 128 ms 71248 KB Output is correct
26 Correct 179 ms 71124 KB Output is correct
27 Correct 265 ms 71408 KB Output is correct
28 Correct 309 ms 71248 KB Output is correct
29 Correct 390 ms 71288 KB Output is correct
30 Correct 496 ms 71248 KB Output is correct
31 Correct 580 ms 71508 KB Output is correct
32 Correct 622 ms 71812 KB Output is correct
33 Correct 474 ms 71928 KB Output is correct
34 Correct 68 ms 72488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14880 KB Output is correct
2 Correct 2 ms 8540 KB Output is correct
3 Correct 17 ms 8680 KB Output is correct
4 Execution timed out 5048 ms 65304 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14832 KB Output is correct
3 Correct 3 ms 16732 KB Output is correct
4 Correct 8 ms 24924 KB Output is correct
5 Correct 5 ms 24924 KB Output is correct
6 Correct 4 ms 24920 KB Output is correct
7 Correct 4 ms 24920 KB Output is correct
8 Correct 5 ms 26972 KB Output is correct
9 Correct 4 ms 26972 KB Output is correct
10 Correct 5 ms 27188 KB Output is correct
11 Correct 5 ms 26972 KB Output is correct
12 Correct 5 ms 26972 KB Output is correct
13 Correct 5 ms 26972 KB Output is correct
14 Correct 5 ms 26972 KB Output is correct
15 Correct 5 ms 26972 KB Output is correct
16 Correct 4 ms 26972 KB Output is correct
17 Correct 5 ms 26972 KB Output is correct
18 Correct 4 ms 26972 KB Output is correct
19 Correct 4 ms 26972 KB Output is correct
20 Correct 5 ms 27064 KB Output is correct
21 Correct 4 ms 26968 KB Output is correct
22 Correct 4 ms 26972 KB Output is correct
23 Correct 4 ms 26972 KB Output is correct
24 Correct 5 ms 26972 KB Output is correct
25 Correct 4 ms 26972 KB Output is correct
26 Correct 4 ms 26968 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 4 ms 26972 KB Output is correct
29 Correct 5 ms 27100 KB Output is correct
30 Correct 20 ms 31324 KB Output is correct
31 Correct 22 ms 31320 KB Output is correct
32 Correct 32 ms 31320 KB Output is correct
33 Correct 32 ms 31324 KB Output is correct
34 Correct 32 ms 31440 KB Output is correct
35 Correct 53 ms 31324 KB Output is correct
36 Correct 54 ms 31428 KB Output is correct
37 Correct 52 ms 31416 KB Output is correct
38 Correct 33 ms 31320 KB Output is correct
39 Correct 34 ms 31324 KB Output is correct
40 Correct 32 ms 31320 KB Output is correct
41 Correct 57 ms 31320 KB Output is correct
42 Correct 56 ms 31324 KB Output is correct
43 Correct 64 ms 31460 KB Output is correct
44 Correct 31 ms 31320 KB Output is correct
45 Correct 34 ms 31324 KB Output is correct
46 Correct 32 ms 31324 KB Output is correct
47 Correct 55 ms 31324 KB Output is correct
48 Correct 56 ms 31676 KB Output is correct
49 Correct 55 ms 31324 KB Output is correct
50 Correct 28 ms 31436 KB Output is correct
51 Correct 27 ms 31324 KB Output is correct
52 Correct 27 ms 31324 KB Output is correct
53 Correct 26 ms 31444 KB Output is correct
54 Correct 26 ms 31324 KB Output is correct
55 Correct 27 ms 31320 KB Output is correct
56 Correct 16 ms 8540 KB Output is correct
57 Correct 5 ms 31324 KB Output is correct
58 Correct 6 ms 31324 KB Output is correct
59 Correct 2 ms 14684 KB Output is correct
60 Correct 2 ms 8540 KB Output is correct
61 Correct 16 ms 8540 KB Output is correct
62 Execution timed out 5032 ms 66024 KB Time limit exceeded
63 Halted 0 ms 0 KB -