답안 #987665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
987665 2024-05-23T10:12:03 Z snpmrnhlol Tourism (JOI23_tourism) C++17
28 / 100
5000 ms 21620 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector <int> e[N];
vector <pair<int,int>> q2[N];
int sub[N];
int top[N];
int st[N],cnt = 0;
int c[N];
int d[N];
int pr[N];
int ans[N];
int st2[N];
int n,m,q;
void dfs(int node, int p){
    sub[node] = 1;
    pr[node] = p;
    if(p == -1){
        d[node] = 0;
    }else{
        d[node] = d[p] + 1;
    }
    for(auto i:e[node]){
        if(i == p)continue;
        dfs(i, node);
        sub[node]+=sub[i];
    }
}
void dfs2(int node, int p){
    int mxid = -1;
    for(auto i:e[node]){
        if(i == p)continue;
        if(mxid == -1 || sub[mxid] < sub[i]){
            mxid = i;
        }
    }
    st[node] = cnt++;
    st2[cnt - 1] = node;
    if(mxid != -1){
        top[mxid] = top[node];
        dfs2(mxid, node);
    }
    for(auto i:e[node]){
        if(i == p || i == mxid)continue;
        top[i] = i;
        dfs2(i, node);
    }
}
int v[N];
void add(int u,int w,int id){
    u = st[u];
    w = st[w];
    if(u > w)swap(u,w);
    ///segment override
    for(int i = u;i <= w;i++){
        v[i] = id;
    }
}
int get(int pos){
    int r = 0;
    for(int i = 0;i < n;i++){
        //cout<<v[i]<<' '<<st2[i]<<'\n';
        if(pos <= v[i])r++;
    }
    //cout<<'\n';
    return r;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m>>q;
    for(int i = 0;i < n - 1;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        e[a].push_back(b);
        e[b].push_back(a);
        v[i] = -1;
    }
    v[n - 1] = -1;
    dfs(0, -1);
    top[0] = 0;
    dfs2(0, -1);
    for(int i = 0;i < m;i++){
        cin>>c[i];
        c[i]--;
    }
    for(int i = 0;i < q;i++){
        int l,r;
        cin>>l>>r;
        if(l == r){
            ans[i] = 1;
            continue;
        }
        q2[r - 1].push_back({l - 1,i});
    }
    for(int i = 1;i < m;i++){
        ///add
        int u = c[i],w = c[i - 1];
        while(top[u] != top[w]){
            if(d[top[u]] > d[top[w]])swap(u,w);
            //cout<<w<<' '<<top[w]<<' '<<i - 1<<'\n';
            add(w,top[w],i - 1);
            w = pr[top[w]];
        }
        //cout<<u<<' '<<w<<' '<<i - 1<<'\n';
        add(u,w,i - 1);
        ///queries
        for(auto j:q2[i]){
            ans[j.second] = get(j.first);
        }
    }
    for(int i = 0;i < q;i++){
        cout<<ans[i]<<'\n';
    }
    return 0;
}
/**
7 2 1
1 2
1 3
2 4
2 5
3 6
3 7
4 5
1 2
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 3 ms 8500 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 4 ms 8756 KB Output is correct
15 Correct 3 ms 8280 KB Output is correct
16 Correct 3 ms 8540 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8308 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 3 ms 8280 KB Output is correct
23 Correct 3 ms 8284 KB Output is correct
24 Correct 3 ms 8284 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 3 ms 8284 KB Output is correct
27 Correct 4 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 3 ms 8500 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 4 ms 8756 KB Output is correct
15 Correct 3 ms 8280 KB Output is correct
16 Correct 3 ms 8540 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8308 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 3 ms 8280 KB Output is correct
23 Correct 3 ms 8284 KB Output is correct
24 Correct 3 ms 8284 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 3 ms 8284 KB Output is correct
27 Correct 4 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8280 KB Output is correct
30 Correct 4 ms 8540 KB Output is correct
31 Correct 6 ms 8540 KB Output is correct
32 Correct 6 ms 8792 KB Output is correct
33 Correct 7 ms 8540 KB Output is correct
34 Correct 6 ms 8540 KB Output is correct
35 Correct 6 ms 8512 KB Output is correct
36 Correct 7 ms 8540 KB Output is correct
37 Correct 6 ms 8540 KB Output is correct
38 Correct 8 ms 8756 KB Output is correct
39 Correct 8 ms 8540 KB Output is correct
40 Correct 7 ms 8540 KB Output is correct
41 Correct 7 ms 8540 KB Output is correct
42 Correct 7 ms 8792 KB Output is correct
43 Correct 7 ms 8724 KB Output is correct
44 Correct 8 ms 8540 KB Output is correct
45 Correct 7 ms 8536 KB Output is correct
46 Correct 7 ms 8540 KB Output is correct
47 Correct 7 ms 8792 KB Output is correct
48 Correct 7 ms 8540 KB Output is correct
49 Correct 7 ms 8536 KB Output is correct
50 Correct 6 ms 8540 KB Output is correct
51 Correct 6 ms 8540 KB Output is correct
52 Correct 6 ms 8540 KB Output is correct
53 Correct 7 ms 8540 KB Output is correct
54 Correct 6 ms 8540 KB Output is correct
55 Correct 7 ms 8536 KB Output is correct
56 Correct 3 ms 8540 KB Output is correct
57 Correct 4 ms 8372 KB Output is correct
58 Correct 4 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8280 KB Output is correct
2 Correct 2 ms 8368 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 3691 ms 16536 KB Output is correct
5 Correct 4328 ms 19024 KB Output is correct
6 Correct 4716 ms 20308 KB Output is correct
7 Execution timed out 5033 ms 21620 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8284 KB Output is correct
2 Correct 91 ms 10484 KB Output is correct
3 Correct 135 ms 11852 KB Output is correct
4 Correct 116 ms 11856 KB Output is correct
5 Correct 54 ms 13392 KB Output is correct
6 Correct 56 ms 13396 KB Output is correct
7 Correct 57 ms 13392 KB Output is correct
8 Correct 58 ms 13396 KB Output is correct
9 Correct 62 ms 13620 KB Output is correct
10 Correct 87 ms 13768 KB Output is correct
11 Correct 116 ms 13636 KB Output is correct
12 Correct 242 ms 13752 KB Output is correct
13 Correct 720 ms 13912 KB Output is correct
14 Correct 1745 ms 14808 KB Output is correct
15 Correct 92 ms 14948 KB Output is correct
16 Correct 687 ms 14128 KB Output is correct
17 Correct 675 ms 14044 KB Output is correct
18 Correct 697 ms 14164 KB Output is correct
19 Correct 110 ms 13652 KB Output is correct
20 Correct 113 ms 13656 KB Output is correct
21 Correct 103 ms 13392 KB Output is correct
22 Correct 103 ms 13600 KB Output is correct
23 Correct 114 ms 13656 KB Output is correct
24 Correct 110 ms 13660 KB Output is correct
25 Correct 127 ms 13636 KB Output is correct
26 Correct 120 ms 13696 KB Output is correct
27 Correct 139 ms 13688 KB Output is correct
28 Correct 186 ms 13568 KB Output is correct
29 Correct 234 ms 13648 KB Output is correct
30 Correct 430 ms 13900 KB Output is correct
31 Correct 731 ms 14080 KB Output is correct
32 Correct 1341 ms 14496 KB Output is correct
33 Correct 2125 ms 15180 KB Output is correct
34 Correct 133 ms 14880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8284 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 3370 ms 12884 KB Output is correct
5 Correct 3294 ms 14980 KB Output is correct
6 Execution timed out 5043 ms 15700 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 3 ms 8284 KB Output is correct
3 Correct 2 ms 8284 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 4 ms 8284 KB Output is correct
7 Correct 4 ms 8284 KB Output is correct
8 Correct 4 ms 8284 KB Output is correct
9 Correct 3 ms 8500 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 4 ms 8756 KB Output is correct
15 Correct 3 ms 8280 KB Output is correct
16 Correct 3 ms 8540 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8308 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 3 ms 8284 KB Output is correct
22 Correct 3 ms 8280 KB Output is correct
23 Correct 3 ms 8284 KB Output is correct
24 Correct 3 ms 8284 KB Output is correct
25 Correct 3 ms 8284 KB Output is correct
26 Correct 3 ms 8284 KB Output is correct
27 Correct 4 ms 8284 KB Output is correct
28 Correct 3 ms 8284 KB Output is correct
29 Correct 3 ms 8280 KB Output is correct
30 Correct 4 ms 8540 KB Output is correct
31 Correct 6 ms 8540 KB Output is correct
32 Correct 6 ms 8792 KB Output is correct
33 Correct 7 ms 8540 KB Output is correct
34 Correct 6 ms 8540 KB Output is correct
35 Correct 6 ms 8512 KB Output is correct
36 Correct 7 ms 8540 KB Output is correct
37 Correct 6 ms 8540 KB Output is correct
38 Correct 8 ms 8756 KB Output is correct
39 Correct 8 ms 8540 KB Output is correct
40 Correct 7 ms 8540 KB Output is correct
41 Correct 7 ms 8540 KB Output is correct
42 Correct 7 ms 8792 KB Output is correct
43 Correct 7 ms 8724 KB Output is correct
44 Correct 8 ms 8540 KB Output is correct
45 Correct 7 ms 8536 KB Output is correct
46 Correct 7 ms 8540 KB Output is correct
47 Correct 7 ms 8792 KB Output is correct
48 Correct 7 ms 8540 KB Output is correct
49 Correct 7 ms 8536 KB Output is correct
50 Correct 6 ms 8540 KB Output is correct
51 Correct 6 ms 8540 KB Output is correct
52 Correct 6 ms 8540 KB Output is correct
53 Correct 7 ms 8540 KB Output is correct
54 Correct 6 ms 8540 KB Output is correct
55 Correct 7 ms 8536 KB Output is correct
56 Correct 3 ms 8540 KB Output is correct
57 Correct 4 ms 8372 KB Output is correct
58 Correct 4 ms 8540 KB Output is correct
59 Correct 2 ms 8280 KB Output is correct
60 Correct 2 ms 8368 KB Output is correct
61 Correct 3 ms 8536 KB Output is correct
62 Correct 3691 ms 16536 KB Output is correct
63 Correct 4328 ms 19024 KB Output is correct
64 Correct 4716 ms 20308 KB Output is correct
65 Execution timed out 5033 ms 21620 KB Time limit exceeded
66 Halted 0 ms 0 KB -