Submission #870624

# Submission time Handle Problem Language Result Execution time Memory
870624 2023-11-08T15:10:41 Z TahirAliyev Paths (BOI18_paths) C++17
23 / 100
3000 ms 62544 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int, int>
#define oo 1e18

const int MAX = 2e5 + 5;

vector<int> g[MAX];

ll dp[32][MAX];
int c[MAX];
int n, m, k;

ll rec(int node, int mask){
    if(dp[mask][node] != -1) return dp[mask][node];
    mask |= (1 << c[node]);
    ll ans = 0;
    if(__popcount(mask) >= 2) ans++;
    for(int to : g[node]){
        if(mask & (1 << c[to])){
            continue;
        }
        ans += rec(to, mask);
    }
    return dp[mask][node] = ans;
}

int main(){
    memset(dp, -1, sizeof(dp));
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++){
        cin >> c[i];
        c[i]--;
    }
    for(int i = 1; i <= m; i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans += rec(i, 0);
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 55640 KB Output is correct
2 Correct 9 ms 55644 KB Output is correct
3 Correct 8 ms 55644 KB Output is correct
4 Correct 7 ms 55764 KB Output is correct
5 Correct 7 ms 55644 KB Output is correct
6 Correct 7 ms 55788 KB Output is correct
7 Correct 7 ms 55644 KB Output is correct
8 Correct 8 ms 55640 KB Output is correct
9 Correct 7 ms 55644 KB Output is correct
10 Correct 7 ms 55716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2156 ms 62544 KB Output is correct
2 Execution timed out 3059 ms 61400 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 55640 KB Output is correct
2 Correct 9 ms 55644 KB Output is correct
3 Correct 8 ms 55644 KB Output is correct
4 Correct 7 ms 55764 KB Output is correct
5 Correct 7 ms 55644 KB Output is correct
6 Correct 7 ms 55788 KB Output is correct
7 Correct 7 ms 55644 KB Output is correct
8 Correct 8 ms 55640 KB Output is correct
9 Correct 7 ms 55644 KB Output is correct
10 Correct 7 ms 55716 KB Output is correct
11 Correct 2156 ms 62544 KB Output is correct
12 Execution timed out 3059 ms 61400 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 55644 KB Output is correct
2 Execution timed out 3091 ms 57648 KB Time limit exceeded
3 Halted 0 ms 0 KB -