Submission #319319

# Submission time Handle Problem Language Result Execution time Memory
319319 2020-11-04T17:36:15 Z OttoTheDino Paths (BOI18_paths) C++17
53 / 100
304 ms 60440 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(n)      for (int i = 0; i < n; ++i)
#define rep2(n)     for (int j = 0; j < n; ++j)
#define mp          make_pair
#define pb          push_back
#define fi          first
#define se          second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<double, double> dd;

const int mxn = 3e5+5, mxa = 32;

ll dp[mxn][mxa], col[mxn];
vi neibs[mxn];

ll f (int c, int C) {
    if (dp[c][C]!=-1) return dp[c][C];
    ll res = C!=0, cur = C|(1<<col[c]);
    for (int v : neibs[c]) if (((1<<col[v])&cur)==0) res += f (v, cur);
    
    dp[c][C] = res;
    return res;
}

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

    memset(dp, -1, mxn*mxa*sizeof(int));
    int n, m, k, a, b;
    cin >> n >> m >> k;
    rep (n) {
       cin >> col[i];
       col[i]--;
    }
    rep (m) {
        cin >> a >> b;
        neibs[a-1].pb(b-1);
        neibs[b-1].pb(a-1);
    }
    
    ll ans = 0;
    rep (n) ans += f(i, 0);

    cout << ans << "\n";

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 24 ms 45056 KB Output is correct
2 Correct 24 ms 45036 KB Output is correct
3 Correct 24 ms 44920 KB Output is correct
4 Correct 25 ms 45036 KB Output is correct
5 Correct 24 ms 45036 KB Output is correct
6 Correct 23 ms 44928 KB Output is correct
7 Correct 23 ms 45036 KB Output is correct
8 Correct 23 ms 44900 KB Output is correct
9 Correct 24 ms 45036 KB Output is correct
10 Correct 23 ms 44908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 51556 KB Output is correct
2 Correct 94 ms 50908 KB Output is correct
3 Incorrect 304 ms 60440 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 45056 KB Output is correct
2 Correct 24 ms 45036 KB Output is correct
3 Correct 24 ms 44920 KB Output is correct
4 Correct 25 ms 45036 KB Output is correct
5 Correct 24 ms 45036 KB Output is correct
6 Correct 23 ms 44928 KB Output is correct
7 Correct 23 ms 45036 KB Output is correct
8 Correct 23 ms 44900 KB Output is correct
9 Correct 24 ms 45036 KB Output is correct
10 Correct 23 ms 44908 KB Output is correct
11 Correct 105 ms 51556 KB Output is correct
12 Correct 94 ms 50908 KB Output is correct
13 Incorrect 304 ms 60440 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 44948 KB Output is correct
2 Correct 64 ms 46820 KB Output is correct
3 Correct 49 ms 46848 KB Output is correct
4 Correct 113 ms 49900 KB Output is correct
5 Correct 81 ms 50652 KB Output is correct
6 Correct 155 ms 50020 KB Output is correct
7 Correct 51 ms 46820 KB Output is correct
8 Correct 133 ms 49892 KB Output is correct
9 Correct 87 ms 50652 KB Output is correct
10 Correct 121 ms 50788 KB Output is correct
11 Correct 126 ms 48352 KB Output is correct
12 Correct 92 ms 49628 KB Output is correct
13 Correct 120 ms 48612 KB Output is correct
14 Correct 152 ms 49892 KB Output is correct
15 Correct 123 ms 50020 KB Output is correct
16 Correct 23 ms 45036 KB Output is correct
17 Correct 24 ms 44908 KB Output is correct
18 Correct 24 ms 44908 KB Output is correct
19 Correct 24 ms 45036 KB Output is correct
20 Correct 23 ms 45036 KB Output is correct
21 Correct 23 ms 45036 KB Output is correct
22 Correct 23 ms 45028 KB Output is correct
23 Correct 24 ms 45028 KB Output is correct
24 Correct 24 ms 44908 KB Output is correct
25 Correct 23 ms 44908 KB Output is correct