Submission #1090916

# Submission time Handle Problem Language Result Execution time Memory
1090916 2024-09-19T07:16:10 Z underwaterkillerwhale Tourism (JOI23_tourism) C++17
10 / 100
313 ms 36832 KB
#include <bits/stdc++.h>
#define ll              long long
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
#define iter(id, v)     for(auto id : v)
#define fs              first
#define se              second
#define MP              make_pair
#define pb              push_back
#define bit(msk, i)     ((msk >> i) & 1)
#define SZ(v)           (ll)v.size()
#define ALL(v)          v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 1e6 + 7;
const int Mod = 1e9 + 2022; ///loonf mod sai
const int INF = 1e9;
const ll BASE = 137;
const int szBL = 350;

int n, m, Q;
vector<int> ke[N];
pii qr[N];
int C[N];

int high[N], par[N][25];

void pdfs (int u, int p) {
    high[u] = high[p] + 1;
    par[u][0] = p;
    rep (i, 1, 20) par[u][i] = par[par[u][i - 1]][i - 1];
    iter (&v, ke[u]) {
        if (v != p) {
            pdfs(v, u);
        }
    }
}

int LCA (int u, int v) {
    if (high[u] > high[v]) swap(u, v);
    rep (i, 0, 20) if (bit(high[v] - high[u], i)) v = par[v][i];
    if (v == u) return v;
    reb (i, 20, 0) if (par[u][i] != par[v][i]) v = par[v][i], u = par[u][i];
    return par[u][0];
}

namespace sub2 {

    int pre[N];

    void dfs (int u, int p, int &res) {
        iter (&v, ke[u]) {
            if (v != p) {
                dfs(v, u, res);
                pre[u] += pre[v];
            }
        }
        if (pre[u] > 0) ++res;
    }

    void solution () {
        rep (q, 1, Q) {
            rep (i, 1, n) pre[i] = 0;
            int L = qr[q].fs, R = qr[q].se;
            int Lca = C[L];
            rep (i, L, R) {
                Lca = LCA(Lca, C[i]);
            }
            rep (i, L, R) {
                pre[C[i]]++;
                pre[par[Lca][0]]--;
            }
            int res = 0;
            dfs(1, 0, res);
            cout << res <<"\n";
        }

    }

}

void solution() {
    cin >> n >> m >> Q;
    rep (i, 1, n - 1) {
        int u, v;
        cin >> u >> v;
        ke[u].pb(v);
        ke[v].pb(u);
    }
    rep (i, 1, m) cin >> C[i];
    rep (i, 1, Q) cin >> qr[i].fs >> qr[i].se;
    pdfs(1, 0);
    if (n <= 2000 && m <= 2000 && Q <= 2000) sub2 :: solution();

}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug +8
chu y break hay return se lam hong logic
xet transition cua i va i + 1
construct ket qua
chu y truong hop : KHONG CO GI

ko làm được

hướng 1: đổi hướng làm
hướng 2: đưa ra nhận xét



2 3 2
0 0
1 0
1 1
0 1
0 2
1 2
0 5
5 0




*/

Compilation message

tourism.cpp: In function 'int LCA(int, int)':
tourism.cpp:47:36: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   47 |     rep (i, 0, 20) if (bit(high[v] - high[u], i)) v = par[v][i];
      |                            ~~~~~~~~^~~~~~~~~
tourism.cpp:12:27: note: in definition of macro 'bit'
   12 | #define bit(msk, i)     ((msk >> i) & 1)
      |                           ^~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23984 KB Output is correct
3 Correct 10 ms 23992 KB Output is correct
4 Correct 14 ms 23984 KB Output is correct
5 Correct 10 ms 23872 KB Output is correct
6 Correct 12 ms 23904 KB Output is correct
7 Correct 11 ms 23948 KB Output is correct
8 Correct 10 ms 23908 KB Output is correct
9 Correct 11 ms 23904 KB Output is correct
10 Correct 11 ms 23904 KB Output is correct
11 Correct 11 ms 23928 KB Output is correct
12 Correct 12 ms 24032 KB Output is correct
13 Correct 15 ms 23828 KB Output is correct
14 Correct 12 ms 23904 KB Output is correct
15 Correct 12 ms 23908 KB Output is correct
16 Correct 11 ms 24060 KB Output is correct
17 Correct 13 ms 24004 KB Output is correct
18 Correct 11 ms 24040 KB Output is correct
19 Correct 11 ms 23904 KB Output is correct
20 Correct 11 ms 24048 KB Output is correct
21 Correct 11 ms 23904 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 11 ms 23852 KB Output is correct
24 Correct 11 ms 24044 KB Output is correct
25 Correct 11 ms 23908 KB Output is correct
26 Correct 11 ms 23968 KB Output is correct
27 Correct 10 ms 23908 KB Output is correct
28 Correct 10 ms 24008 KB Output is correct
29 Correct 10 ms 23908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23984 KB Output is correct
3 Correct 10 ms 23992 KB Output is correct
4 Correct 14 ms 23984 KB Output is correct
5 Correct 10 ms 23872 KB Output is correct
6 Correct 12 ms 23904 KB Output is correct
7 Correct 11 ms 23948 KB Output is correct
8 Correct 10 ms 23908 KB Output is correct
9 Correct 11 ms 23904 KB Output is correct
10 Correct 11 ms 23904 KB Output is correct
11 Correct 11 ms 23928 KB Output is correct
12 Correct 12 ms 24032 KB Output is correct
13 Correct 15 ms 23828 KB Output is correct
14 Correct 12 ms 23904 KB Output is correct
15 Correct 12 ms 23908 KB Output is correct
16 Correct 11 ms 24060 KB Output is correct
17 Correct 13 ms 24004 KB Output is correct
18 Correct 11 ms 24040 KB Output is correct
19 Correct 11 ms 23904 KB Output is correct
20 Correct 11 ms 24048 KB Output is correct
21 Correct 11 ms 23904 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 11 ms 23852 KB Output is correct
24 Correct 11 ms 24044 KB Output is correct
25 Correct 11 ms 23908 KB Output is correct
26 Correct 11 ms 23968 KB Output is correct
27 Correct 10 ms 23908 KB Output is correct
28 Correct 10 ms 24008 KB Output is correct
29 Correct 10 ms 23908 KB Output is correct
30 Correct 51 ms 24220 KB Output is correct
31 Correct 68 ms 24216 KB Output is correct
32 Correct 100 ms 24160 KB Output is correct
33 Correct 101 ms 24160 KB Output is correct
34 Correct 106 ms 24160 KB Output is correct
35 Correct 167 ms 24308 KB Output is correct
36 Correct 166 ms 24156 KB Output is correct
37 Correct 170 ms 24156 KB Output is correct
38 Correct 123 ms 24412 KB Output is correct
39 Correct 125 ms 24664 KB Output is correct
40 Correct 124 ms 24408 KB Output is correct
41 Correct 312 ms 24408 KB Output is correct
42 Correct 313 ms 24408 KB Output is correct
43 Correct 301 ms 24412 KB Output is correct
44 Correct 124 ms 24408 KB Output is correct
45 Correct 112 ms 24156 KB Output is correct
46 Correct 120 ms 24156 KB Output is correct
47 Correct 280 ms 24156 KB Output is correct
48 Correct 261 ms 24336 KB Output is correct
49 Correct 274 ms 24152 KB Output is correct
50 Correct 68 ms 24316 KB Output is correct
51 Correct 59 ms 24152 KB Output is correct
52 Correct 62 ms 24152 KB Output is correct
53 Correct 58 ms 24156 KB Output is correct
54 Correct 58 ms 24156 KB Output is correct
55 Correct 58 ms 24156 KB Output is correct
56 Correct 39 ms 23900 KB Output is correct
57 Correct 34 ms 24156 KB Output is correct
58 Correct 36 ms 24152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 12 ms 23952 KB Output is correct
3 Correct 38 ms 24032 KB Output is correct
4 Incorrect 35 ms 36832 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23980 KB Output is correct
2 Incorrect 30 ms 32336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 10 ms 23900 KB Output is correct
3 Correct 34 ms 24024 KB Output is correct
4 Incorrect 41 ms 34568 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23900 KB Output is correct
2 Correct 10 ms 23984 KB Output is correct
3 Correct 10 ms 23992 KB Output is correct
4 Correct 14 ms 23984 KB Output is correct
5 Correct 10 ms 23872 KB Output is correct
6 Correct 12 ms 23904 KB Output is correct
7 Correct 11 ms 23948 KB Output is correct
8 Correct 10 ms 23908 KB Output is correct
9 Correct 11 ms 23904 KB Output is correct
10 Correct 11 ms 23904 KB Output is correct
11 Correct 11 ms 23928 KB Output is correct
12 Correct 12 ms 24032 KB Output is correct
13 Correct 15 ms 23828 KB Output is correct
14 Correct 12 ms 23904 KB Output is correct
15 Correct 12 ms 23908 KB Output is correct
16 Correct 11 ms 24060 KB Output is correct
17 Correct 13 ms 24004 KB Output is correct
18 Correct 11 ms 24040 KB Output is correct
19 Correct 11 ms 23904 KB Output is correct
20 Correct 11 ms 24048 KB Output is correct
21 Correct 11 ms 23904 KB Output is correct
22 Correct 11 ms 23900 KB Output is correct
23 Correct 11 ms 23852 KB Output is correct
24 Correct 11 ms 24044 KB Output is correct
25 Correct 11 ms 23908 KB Output is correct
26 Correct 11 ms 23968 KB Output is correct
27 Correct 10 ms 23908 KB Output is correct
28 Correct 10 ms 24008 KB Output is correct
29 Correct 10 ms 23908 KB Output is correct
30 Correct 51 ms 24220 KB Output is correct
31 Correct 68 ms 24216 KB Output is correct
32 Correct 100 ms 24160 KB Output is correct
33 Correct 101 ms 24160 KB Output is correct
34 Correct 106 ms 24160 KB Output is correct
35 Correct 167 ms 24308 KB Output is correct
36 Correct 166 ms 24156 KB Output is correct
37 Correct 170 ms 24156 KB Output is correct
38 Correct 123 ms 24412 KB Output is correct
39 Correct 125 ms 24664 KB Output is correct
40 Correct 124 ms 24408 KB Output is correct
41 Correct 312 ms 24408 KB Output is correct
42 Correct 313 ms 24408 KB Output is correct
43 Correct 301 ms 24412 KB Output is correct
44 Correct 124 ms 24408 KB Output is correct
45 Correct 112 ms 24156 KB Output is correct
46 Correct 120 ms 24156 KB Output is correct
47 Correct 280 ms 24156 KB Output is correct
48 Correct 261 ms 24336 KB Output is correct
49 Correct 274 ms 24152 KB Output is correct
50 Correct 68 ms 24316 KB Output is correct
51 Correct 59 ms 24152 KB Output is correct
52 Correct 62 ms 24152 KB Output is correct
53 Correct 58 ms 24156 KB Output is correct
54 Correct 58 ms 24156 KB Output is correct
55 Correct 58 ms 24156 KB Output is correct
56 Correct 39 ms 23900 KB Output is correct
57 Correct 34 ms 24156 KB Output is correct
58 Correct 36 ms 24152 KB Output is correct
59 Correct 11 ms 23900 KB Output is correct
60 Correct 12 ms 23952 KB Output is correct
61 Correct 38 ms 24032 KB Output is correct
62 Incorrect 35 ms 36832 KB Output isn't correct
63 Halted 0 ms 0 KB -