답안 #950053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
950053 2024-03-20T04:27:10 Z Abito Tourism (JOI23_tourism) C++17
0 / 100
15 ms 860 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=2005;
int n,par[N],b[N],m,q,euler[2*N],c,dis[N],f[N],lg[2*N];
vector<int> adj[N];
bool vis[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--){
        int l,r;
        cin>>l>>r;
        int lca=b[l];
        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]>=lca && !vis[x]){
                vis[x]=1;
                x=par[x];
            }
        }
        int ans=0;
        for (int i=1;i<=n;i++) ans+=vis[i],vis[i]=0;
        cout<<ans<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 15 ms 348 KB Output is correct
4 Runtime error 1 ms 860 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 15 ms 348 KB Output is correct
4 Runtime error 1 ms 812 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -