답안 #392899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392899 2021-04-22T09:00:54 Z arujbansal Paths (BOI18_paths) C++17
100 / 100
446 ms 62384 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>

using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define int long long

const int MXN = 1e5 + 5, INF = 1e9 + 5;

void solve() {
    int N, M, K;
    cin >> N >> M >> K;

    vector<vector<int>> dp(1 << K, vector<int>(N, 0));
    vector<int> colour(N);

    for (int i = 0; i < N; i++) {
        cin >> colour[i];
        colour[i]--;

        dp[1 << colour[i]][i] = 1;
    }

    vector<int> g[N];
    for (int i = 0; i < M; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;

        g[u].push_back(v);
        g[v].push_back(u);
    }

    int ans = 0;

    for (int mask = 0; mask < (1 << K); mask++) {
        for (int u = 0; u < N; u++) {
            if ((mask >> colour[u]) & 1) {
                for (const auto &v : g[u])
                    dp[mask][u] += dp[mask ^ (1 << colour[u])][v];

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

    cout << ans - N;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int TC = 1;
    // cin >> TC;
    while (TC--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 7876 KB Output is correct
2 Correct 59 ms 7428 KB Output is correct
3 Correct 341 ms 39040 KB Output is correct
4 Correct 111 ms 10304 KB Output is correct
5 Correct 111 ms 9764 KB Output is correct
6 Correct 215 ms 28004 KB Output is correct
7 Correct 318 ms 43416 KB Output is correct
8 Correct 336 ms 44148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 75 ms 7876 KB Output is correct
12 Correct 59 ms 7428 KB Output is correct
13 Correct 341 ms 39040 KB Output is correct
14 Correct 111 ms 10304 KB Output is correct
15 Correct 111 ms 9764 KB Output is correct
16 Correct 215 ms 28004 KB Output is correct
17 Correct 318 ms 43416 KB Output is correct
18 Correct 336 ms 44148 KB Output is correct
19 Correct 79 ms 10812 KB Output is correct
20 Correct 61 ms 9668 KB Output is correct
21 Correct 338 ms 43584 KB Output is correct
22 Correct 131 ms 13596 KB Output is correct
23 Correct 106 ms 13144 KB Output is correct
24 Correct 218 ms 32076 KB Output is correct
25 Correct 328 ms 43616 KB Output is correct
26 Correct 340 ms 43924 KB Output is correct
27 Correct 67 ms 9768 KB Output is correct
28 Correct 96 ms 12996 KB Output is correct
29 Correct 446 ms 62368 KB Output is correct
30 Correct 261 ms 36656 KB Output is correct
31 Correct 275 ms 36704 KB Output is correct
32 Correct 442 ms 62384 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 24 ms 2636 KB Output is correct
3 Correct 20 ms 3184 KB Output is correct
4 Correct 73 ms 14596 KB Output is correct
5 Correct 57 ms 14892 KB Output is correct
6 Correct 143 ms 33328 KB Output is correct
7 Correct 21 ms 3276 KB Output is correct
8 Correct 98 ms 20792 KB Output is correct
9 Correct 67 ms 21204 KB Output is correct
10 Correct 82 ms 21456 KB Output is correct
11 Correct 71 ms 18112 KB Output is correct
12 Correct 77 ms 25892 KB Output is correct
13 Correct 73 ms 18828 KB Output is correct
14 Correct 143 ms 33444 KB Output is correct
15 Correct 160 ms 33628 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 316 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct