답안 #889631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889631 2023-12-20T04:08:45 Z vjudge1 Tourism (JOI23_tourism) C++17
5 / 100
5000 ms 7760 KB
#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);
    int n,m,qq;
    cin>>n>>m>>qq;
    vector <int> g[n+1];
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    vector <int> c(m+1);
    for(int i=1;i<=m;i++){
        cin>>c[i];
    }
    queue <int> q;
    while(qq--){
        int l,r;
        cin>>l>>r;
        set <int> st;
        if(l==r)st.insert(l);
        for(int i=l;i<r;i++){
            vector <int> d(n+1,-1);
            vector <int> p(n+1);
            q.push(c[i]);
            d[c[i]]=1;
            while(!q.empty()){
                int v=q.front();
                q.pop();
                for(auto to : g[v]){
                    if(d[to]==-1){
                        d[to]=1;
                        p[to]=v;
                        q.push(to);
                    }
                }
            }
            int x=c[i+1];
            st.insert(x);st.insert(c[i]);
            while(x!=c[i]){
                x=p[x];
                st.insert(x);
            }
        }
        cout<<st.size()<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 39 ms 456 KB Output is correct
5 Correct 33 ms 348 KB Output is correct
6 Correct 25 ms 348 KB Output is correct
7 Correct 33 ms 600 KB Output is correct
8 Correct 32 ms 348 KB Output is correct
9 Correct 94 ms 348 KB Output is correct
10 Correct 87 ms 344 KB Output is correct
11 Correct 95 ms 348 KB Output is correct
12 Correct 257 ms 344 KB Output is correct
13 Correct 257 ms 348 KB Output is correct
14 Correct 246 ms 348 KB Output is correct
15 Correct 131 ms 344 KB Output is correct
16 Correct 124 ms 344 KB Output is correct
17 Correct 146 ms 344 KB Output is correct
18 Correct 125 ms 448 KB Output is correct
19 Correct 123 ms 348 KB Output is correct
20 Correct 132 ms 444 KB Output is correct
21 Correct 56 ms 348 KB Output is correct
22 Correct 54 ms 348 KB Output is correct
23 Correct 51 ms 348 KB Output is correct
24 Correct 53 ms 348 KB Output is correct
25 Correct 53 ms 348 KB Output is correct
26 Correct 55 ms 344 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 39 ms 456 KB Output is correct
5 Correct 33 ms 348 KB Output is correct
6 Correct 25 ms 348 KB Output is correct
7 Correct 33 ms 600 KB Output is correct
8 Correct 32 ms 348 KB Output is correct
9 Correct 94 ms 348 KB Output is correct
10 Correct 87 ms 344 KB Output is correct
11 Correct 95 ms 348 KB Output is correct
12 Correct 257 ms 344 KB Output is correct
13 Correct 257 ms 348 KB Output is correct
14 Correct 246 ms 348 KB Output is correct
15 Correct 131 ms 344 KB Output is correct
16 Correct 124 ms 344 KB Output is correct
17 Correct 146 ms 344 KB Output is correct
18 Correct 125 ms 448 KB Output is correct
19 Correct 123 ms 348 KB Output is correct
20 Correct 132 ms 444 KB Output is correct
21 Correct 56 ms 348 KB Output is correct
22 Correct 54 ms 348 KB Output is correct
23 Correct 51 ms 348 KB Output is correct
24 Correct 53 ms 348 KB Output is correct
25 Correct 53 ms 348 KB Output is correct
26 Correct 55 ms 344 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Execution timed out 5028 ms 592 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 52 ms 348 KB Output is correct
4 Execution timed out 5051 ms 7760 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 5074 ms 5108 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 50 ms 348 KB Output is correct
4 Execution timed out 5057 ms 7132 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 39 ms 456 KB Output is correct
5 Correct 33 ms 348 KB Output is correct
6 Correct 25 ms 348 KB Output is correct
7 Correct 33 ms 600 KB Output is correct
8 Correct 32 ms 348 KB Output is correct
9 Correct 94 ms 348 KB Output is correct
10 Correct 87 ms 344 KB Output is correct
11 Correct 95 ms 348 KB Output is correct
12 Correct 257 ms 344 KB Output is correct
13 Correct 257 ms 348 KB Output is correct
14 Correct 246 ms 348 KB Output is correct
15 Correct 131 ms 344 KB Output is correct
16 Correct 124 ms 344 KB Output is correct
17 Correct 146 ms 344 KB Output is correct
18 Correct 125 ms 448 KB Output is correct
19 Correct 123 ms 348 KB Output is correct
20 Correct 132 ms 444 KB Output is correct
21 Correct 56 ms 348 KB Output is correct
22 Correct 54 ms 348 KB Output is correct
23 Correct 51 ms 348 KB Output is correct
24 Correct 53 ms 348 KB Output is correct
25 Correct 53 ms 348 KB Output is correct
26 Correct 55 ms 344 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Execution timed out 5028 ms 592 KB Time limit exceeded
31 Halted 0 ms 0 KB -