답안 #887676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887676 2023-12-15T02:31:53 Z votranngocvy Paths (BOI18_paths) C++14
100 / 100
257 ms 103096 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 3e5 + 5;
int n,m,k,a[N];
vector<int>g[N];

namespace sub1 {
    int ans = 0;
    bool vis[10];
    void dfs(int u) {
        vis[a[u]] = true;
        for (auto v: g[u]) {
            if (vis[a[v]]) continue;
            ans++;
            dfs(v);
        }
        vis[a[u]] = false;
    }
    void solve() {
        for (int i = 1; i <= n; i++) dfs(i);
        cout << ans << "\n";
    }
}

namespace sol {
    int dp[N][35];
    void solve() {
        for (int i = 1; i <= n; i++) dp[i][(1 << a[i])] = 1;
        for (int mask = 0; mask < (1 << k); mask++) {
            for (int u = 1; u <= n; u++) {
                if (dp[u][mask] == 0) continue;
                for (auto v: g[u]) {
                    if (mask & (1 << a[v])) continue;
                    dp[v][mask | (1 << a[v])] += dp[u][mask];
                }
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; i++)
            for (int mask = 0; mask < (1 << k); mask++)
                if (__builtin_popcount(mask) >= 2) ans += dp[i][mask];
        cout << ans << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 1; i <= m; i++) {
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    sol::solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10688 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10680 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 19892 KB Output is correct
2 Correct 47 ms 19952 KB Output is correct
3 Correct 209 ms 102548 KB Output is correct
4 Correct 84 ms 27184 KB Output is correct
5 Correct 91 ms 26996 KB Output is correct
6 Correct 154 ms 75304 KB Output is correct
7 Correct 213 ms 102548 KB Output is correct
8 Correct 231 ms 103096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10688 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10680 KB Output is correct
6 Correct 2 ms 10588 KB Output is correct
7 Correct 2 ms 10588 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 55 ms 19892 KB Output is correct
12 Correct 47 ms 19952 KB Output is correct
13 Correct 209 ms 102548 KB Output is correct
14 Correct 84 ms 27184 KB Output is correct
15 Correct 91 ms 26996 KB Output is correct
16 Correct 154 ms 75304 KB Output is correct
17 Correct 213 ms 102548 KB Output is correct
18 Correct 231 ms 103096 KB Output is correct
19 Correct 51 ms 19896 KB Output is correct
20 Correct 48 ms 19820 KB Output is correct
21 Correct 217 ms 102480 KB Output is correct
22 Correct 75 ms 27148 KB Output is correct
23 Correct 61 ms 27216 KB Output is correct
24 Correct 133 ms 75460 KB Output is correct
25 Correct 192 ms 102500 KB Output is correct
26 Correct 205 ms 103096 KB Output is correct
27 Correct 52 ms 20060 KB Output is correct
28 Correct 67 ms 21332 KB Output is correct
29 Correct 257 ms 102556 KB Output is correct
30 Correct 171 ms 60608 KB Output is correct
31 Correct 195 ms 60748 KB Output is correct
32 Correct 254 ms 102524 KB Output is correct
33 Correct 2 ms 10588 KB Output is correct
34 Correct 2 ms 10588 KB Output is correct
35 Correct 2 ms 10588 KB Output is correct
36 Correct 2 ms 10736 KB Output is correct
37 Correct 2 ms 10588 KB Output is correct
38 Correct 2 ms 10692 KB Output is correct
39 Correct 2 ms 10588 KB Output is correct
40 Correct 2 ms 10588 KB Output is correct
41 Correct 2 ms 10588 KB Output is correct
42 Correct 2 ms 10588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 34 ms 12892 KB Output is correct
3 Correct 23 ms 12892 KB Output is correct
4 Correct 54 ms 43112 KB Output is correct
5 Correct 43 ms 43468 KB Output is correct
6 Correct 95 ms 43120 KB Output is correct
7 Correct 19 ms 12892 KB Output is correct
8 Correct 64 ms 43060 KB Output is correct
9 Correct 49 ms 43476 KB Output is correct
10 Correct 54 ms 43104 KB Output is correct
11 Correct 52 ms 27848 KB Output is correct
12 Correct 51 ms 34344 KB Output is correct
13 Correct 53 ms 27980 KB Output is correct
14 Correct 83 ms 43100 KB Output is correct
15 Correct 74 ms 43092 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 2 ms 10588 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10732 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10588 KB Output is correct
22 Correct 2 ms 10584 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 2 ms 10588 KB Output is correct