답안 #796276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796276 2023-07-28T08:46:43 Z Johann Tourism (JOI23_tourism) C++14
10 / 100
5000 ms 22396 KB
#include "bits/stdc++.h"
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int N, M, Q;
vi C;
vector<set<int>> CC;
vvi adj;
vi in, out;
vvi vorg;

// void dfs(int v, int p, int &idx);

int solve(int v, int p, int l, int r)
{
    int ans = 0;
    for (int u : adj[v])
        if (u != p)
            ans += solve(u, v, l, r);
    auto it = CC[v].lower_bound(l);
    if ((it != CC[v].end() && *it < r) || ans)
        ++ans;
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M >> Q;

    adj.resize(N);
    for (int i = 0, a, b; i < N - 1; ++i)
    {
        cin >> a >> b;
        --a, --b;
        adj[a].push_back(b), adj[b].push_back(a);
    }
    int idx = 0;
    in.resize(N), out.resize(N);
    vorg.assign(N, vi(ceil(log2(N) + 1)));
    // dfs(0, 0, idx);

    C.resize(M), CC.resize(N);
    for (int i = 0; i < M; ++i)
    {
        cin >> C[i];
        --C[i];
        CC[C[i]].insert(i);
    }
    for (int i = 0, l, r; i < Q; ++i)
    {
        cin >> l >> r;
        --l;

        cout << solve(C[l], C[l], l, r) << "\n";
    }
}

Compilation message

tourism.cpp: In function 'int main()':
tourism.cpp:42:9: warning: unused variable 'idx' [-Wunused-variable]
   42 |     int idx = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 320 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 320 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 44 ms 596 KB Output is correct
31 Correct 58 ms 724 KB Output is correct
32 Correct 102 ms 1096 KB Output is correct
33 Correct 98 ms 852 KB Output is correct
34 Correct 95 ms 860 KB Output is correct
35 Correct 37 ms 852 KB Output is correct
36 Correct 39 ms 856 KB Output is correct
37 Correct 38 ms 856 KB Output is correct
38 Correct 87 ms 980 KB Output is correct
39 Correct 86 ms 1012 KB Output is correct
40 Correct 92 ms 980 KB Output is correct
41 Correct 51 ms 1008 KB Output is correct
42 Correct 56 ms 1008 KB Output is correct
43 Correct 48 ms 996 KB Output is correct
44 Correct 86 ms 852 KB Output is correct
45 Correct 84 ms 912 KB Output is correct
46 Correct 84 ms 916 KB Output is correct
47 Correct 45 ms 852 KB Output is correct
48 Correct 47 ms 896 KB Output is correct
49 Correct 47 ms 904 KB Output is correct
50 Correct 62 ms 872 KB Output is correct
51 Correct 65 ms 852 KB Output is correct
52 Correct 61 ms 852 KB Output is correct
53 Correct 61 ms 852 KB Output is correct
54 Correct 62 ms 856 KB Output is correct
55 Correct 60 ms 856 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 29 ms 736 KB Output is correct
58 Correct 89 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Execution timed out 5043 ms 22396 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4154 ms 14760 KB Output is correct
3 Execution timed out 5045 ms 17464 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 5044 ms 16724 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 276 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 320 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 320 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 44 ms 596 KB Output is correct
31 Correct 58 ms 724 KB Output is correct
32 Correct 102 ms 1096 KB Output is correct
33 Correct 98 ms 852 KB Output is correct
34 Correct 95 ms 860 KB Output is correct
35 Correct 37 ms 852 KB Output is correct
36 Correct 39 ms 856 KB Output is correct
37 Correct 38 ms 856 KB Output is correct
38 Correct 87 ms 980 KB Output is correct
39 Correct 86 ms 1012 KB Output is correct
40 Correct 92 ms 980 KB Output is correct
41 Correct 51 ms 1008 KB Output is correct
42 Correct 56 ms 1008 KB Output is correct
43 Correct 48 ms 996 KB Output is correct
44 Correct 86 ms 852 KB Output is correct
45 Correct 84 ms 912 KB Output is correct
46 Correct 84 ms 916 KB Output is correct
47 Correct 45 ms 852 KB Output is correct
48 Correct 47 ms 896 KB Output is correct
49 Correct 47 ms 904 KB Output is correct
50 Correct 62 ms 872 KB Output is correct
51 Correct 65 ms 852 KB Output is correct
52 Correct 61 ms 852 KB Output is correct
53 Correct 61 ms 852 KB Output is correct
54 Correct 62 ms 856 KB Output is correct
55 Correct 60 ms 856 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 29 ms 736 KB Output is correct
58 Correct 89 ms 852 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Execution timed out 5043 ms 22396 KB Time limit exceeded
63 Halted 0 ms 0 KB -