Submission #767912

# Submission time Handle Problem Language Result Execution time Memory
767912 2023-06-27T09:28:39 Z raysh07 Paths (BOI18_paths) C++17
100 / 100
414 ms 100488 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
int n, m, k;
const int N = 3e5 + 69;
const int K = 5;
int dp[N][1 << K];
vector <int> adj[N];
int a[N];

int cnt(int x){
    if (x == 0) return 0;
    return cnt(x/2) + x % 2;
}

void Solve() 
{
    cin >> n >> m >> k;
    
    for (int i = 1; i <= n; i++) {
        cin >> a[i], a[i]--;
        dp[i][1 << a[i]] = 1;
    }
    
    for (int i = 1; i <= m; i++){
        int u, v; cin >> u >> v;
        
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    for (int it = 2; it <= 5; it++){
        vector <int> ok;
        for (int mask = 1; mask < 32; mask++){
            if (cnt(mask) == it) ok.push_back(mask);
        }
        for (int i = 1; i <= n; i++){
            for (int j : adj[i]){
                for (auto mask : ok){
                    if (mask >> a[i] & 1){
                        dp[i][mask] += dp[j][mask ^ (1 << a[i])];
                    }
                }
            }
        }
    }
    
    int ans = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j < 32; j++){
            ans += dp[i][j];
        }
    }
    
    cout << ans - n << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7304 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7384 KB Output is correct
5 Correct 3 ms 7380 KB Output is correct
6 Correct 3 ms 7388 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 3 ms 7384 KB Output is correct
9 Correct 3 ms 7380 KB Output is correct
10 Correct 3 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 18436 KB Output is correct
2 Correct 52 ms 16972 KB Output is correct
3 Correct 414 ms 99948 KB Output is correct
4 Correct 103 ms 26624 KB Output is correct
5 Correct 104 ms 26564 KB Output is correct
6 Correct 292 ms 71880 KB Output is correct
7 Correct 394 ms 99868 KB Output is correct
8 Correct 402 ms 100488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7304 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 4 ms 7384 KB Output is correct
5 Correct 3 ms 7380 KB Output is correct
6 Correct 3 ms 7388 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 3 ms 7384 KB Output is correct
9 Correct 3 ms 7380 KB Output is correct
10 Correct 3 ms 7380 KB Output is correct
11 Correct 65 ms 18436 KB Output is correct
12 Correct 52 ms 16972 KB Output is correct
13 Correct 414 ms 99948 KB Output is correct
14 Correct 103 ms 26624 KB Output is correct
15 Correct 104 ms 26564 KB Output is correct
16 Correct 292 ms 71880 KB Output is correct
17 Correct 394 ms 99868 KB Output is correct
18 Correct 402 ms 100488 KB Output is correct
19 Correct 68 ms 18680 KB Output is correct
20 Correct 54 ms 16916 KB Output is correct
21 Correct 375 ms 99844 KB Output is correct
22 Correct 104 ms 26572 KB Output is correct
23 Correct 108 ms 26540 KB Output is correct
24 Correct 272 ms 72024 KB Output is correct
25 Correct 392 ms 99788 KB Output is correct
26 Correct 387 ms 100404 KB Output is correct
27 Correct 50 ms 16856 KB Output is correct
28 Correct 74 ms 20900 KB Output is correct
29 Correct 355 ms 99788 KB Output is correct
30 Correct 304 ms 58816 KB Output is correct
31 Correct 273 ms 58964 KB Output is correct
32 Correct 375 ms 99788 KB Output is correct
33 Correct 3 ms 7380 KB Output is correct
34 Correct 3 ms 7380 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 3 ms 7380 KB Output is correct
37 Correct 3 ms 7380 KB Output is correct
38 Correct 4 ms 7388 KB Output is correct
39 Correct 4 ms 7360 KB Output is correct
40 Correct 3 ms 7380 KB Output is correct
41 Correct 3 ms 7380 KB Output is correct
42 Correct 3 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 19 ms 10340 KB Output is correct
3 Correct 19 ms 10336 KB Output is correct
4 Correct 102 ms 38000 KB Output is correct
5 Correct 79 ms 38492 KB Output is correct
6 Correct 106 ms 38120 KB Output is correct
7 Correct 19 ms 10324 KB Output is correct
8 Correct 100 ms 37968 KB Output is correct
9 Correct 80 ms 38496 KB Output is correct
10 Correct 88 ms 38696 KB Output is correct
11 Correct 52 ms 24064 KB Output is correct
12 Correct 65 ms 31200 KB Output is correct
13 Correct 54 ms 24404 KB Output is correct
14 Correct 99 ms 37964 KB Output is correct
15 Correct 114 ms 38140 KB Output is correct
16 Correct 3 ms 7376 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 3 ms 7384 KB Output is correct
20 Correct 3 ms 7372 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 3 ms 7388 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7424 KB Output is correct
25 Correct 3 ms 7380 KB Output is correct