Submission #975159

# Submission time Handle Problem Language Result Execution time Memory
975159 2024-05-04T14:00:05 Z LOLOLO Paths (BOI18_paths) C++14
100 / 100
347 ms 97184 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 3e5 + 100;
ll dp[N][(1 << 5)];
int a[N];
vector <int> ed[N];

ll dfs(int u, int mask) {
    if (mask == 0)
        return 1;

    if (dp[u][mask] != -1)
        return dp[u][mask];

    ll ans = 0;
    for (auto x : ed[u]) {
        if ((a[x] & mask) == a[x]) {
            ans += dfs(x, mask ^ a[x]);
        }
    }

    return dp[u][mask] = ans;
}

ll solve() {
    int n, m, k;
    cin >> n >> m >> k;

    for (int i = 1; i <= n; i++) {
        cin >> a[i]; 
        a[i]--;
        a[i] = (1 << a[i]);
    }

    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        ed[a].pb(b);
        ed[b].pb(a);
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int mask = 1; mask < (1 << k); mask++) {
            if ((a[i] & mask) == a[i] && cntbit(mask) > 1) {
                ans += dfs(i, mask ^ a[i]);
            }
        }
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    mem(dp, -1)
    ;
    int t = 1;
    //cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }

    return 0;
}



 
# Verdict Execution time Memory Grader output
1 Correct 35 ms 83796 KB Output is correct
2 Correct 12 ms 83612 KB Output is correct
3 Correct 13 ms 83856 KB Output is correct
4 Correct 13 ms 84060 KB Output is correct
5 Correct 13 ms 83804 KB Output is correct
6 Correct 12 ms 83804 KB Output is correct
7 Correct 12 ms 83848 KB Output is correct
8 Correct 12 ms 83804 KB Output is correct
9 Correct 12 ms 83700 KB Output is correct
10 Correct 12 ms 83804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 90192 KB Output is correct
2 Correct 52 ms 89688 KB Output is correct
3 Correct 215 ms 96676 KB Output is correct
4 Correct 87 ms 91472 KB Output is correct
5 Correct 68 ms 91608 KB Output is correct
6 Correct 165 ms 94936 KB Output is correct
7 Correct 225 ms 96512 KB Output is correct
8 Correct 220 ms 97168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 83796 KB Output is correct
2 Correct 12 ms 83612 KB Output is correct
3 Correct 13 ms 83856 KB Output is correct
4 Correct 13 ms 84060 KB Output is correct
5 Correct 13 ms 83804 KB Output is correct
6 Correct 12 ms 83804 KB Output is correct
7 Correct 12 ms 83848 KB Output is correct
8 Correct 12 ms 83804 KB Output is correct
9 Correct 12 ms 83700 KB Output is correct
10 Correct 12 ms 83804 KB Output is correct
11 Correct 75 ms 90192 KB Output is correct
12 Correct 52 ms 89688 KB Output is correct
13 Correct 215 ms 96676 KB Output is correct
14 Correct 87 ms 91472 KB Output is correct
15 Correct 68 ms 91608 KB Output is correct
16 Correct 165 ms 94936 KB Output is correct
17 Correct 225 ms 96512 KB Output is correct
18 Correct 220 ms 97168 KB Output is correct
19 Correct 69 ms 90136 KB Output is correct
20 Correct 52 ms 89684 KB Output is correct
21 Correct 213 ms 96592 KB Output is correct
22 Correct 74 ms 91604 KB Output is correct
23 Correct 68 ms 91472 KB Output is correct
24 Correct 140 ms 94916 KB Output is correct
25 Correct 210 ms 96596 KB Output is correct
26 Correct 251 ms 97184 KB Output is correct
27 Correct 62 ms 89680 KB Output is correct
28 Correct 81 ms 90960 KB Output is correct
29 Correct 288 ms 96436 KB Output is correct
30 Correct 187 ms 93636 KB Output is correct
31 Correct 188 ms 93468 KB Output is correct
32 Correct 347 ms 96888 KB Output is correct
33 Correct 12 ms 83800 KB Output is correct
34 Correct 12 ms 83804 KB Output is correct
35 Correct 12 ms 83804 KB Output is correct
36 Correct 13 ms 83692 KB Output is correct
37 Correct 12 ms 83804 KB Output is correct
38 Correct 12 ms 83816 KB Output is correct
39 Correct 12 ms 83672 KB Output is correct
40 Correct 12 ms 83804 KB Output is correct
41 Correct 13 ms 83804 KB Output is correct
42 Correct 14 ms 83844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 83804 KB Output is correct
2 Correct 37 ms 85464 KB Output is correct
3 Correct 26 ms 85596 KB Output is correct
4 Correct 61 ms 87968 KB Output is correct
5 Correct 46 ms 88680 KB Output is correct
6 Correct 106 ms 87800 KB Output is correct
7 Correct 32 ms 85844 KB Output is correct
8 Correct 83 ms 87964 KB Output is correct
9 Correct 63 ms 88680 KB Output is correct
10 Correct 70 ms 88784 KB Output is correct
11 Correct 73 ms 86788 KB Output is correct
12 Correct 65 ms 87896 KB Output is correct
13 Correct 79 ms 86976 KB Output is correct
14 Correct 103 ms 87892 KB Output is correct
15 Correct 100 ms 88056 KB Output is correct
16 Correct 12 ms 83804 KB Output is correct
17 Correct 12 ms 83676 KB Output is correct
18 Correct 13 ms 83712 KB Output is correct
19 Correct 12 ms 83852 KB Output is correct
20 Correct 13 ms 83804 KB Output is correct
21 Correct 12 ms 83804 KB Output is correct
22 Correct 12 ms 83804 KB Output is correct
23 Correct 12 ms 83804 KB Output is correct
24 Correct 12 ms 83800 KB Output is correct
25 Correct 13 ms 83804 KB Output is correct