답안 #702061

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702061 2023-02-22T15:08:32 Z _martynas Paths (BOI18_paths) C++11
100 / 100
544 ms 56676 KB
// Solved on 2022/10/18
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

const int MOD = 1e9+7;

#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

const int MXN = 3e5+5;

int n, m, k;
int A[MXN];
vi adj[MXN];
ll ways[1<<6][MXN];

void transit(int bits) {
    for(int i = 0; i < n; i++) {
        for(int j : adj[i]) {
            for(int b = 0; b < (1<<k); b++) {
                if(__builtin_popcount(b) != bits) continue;
                if(b & (1 << A[j])) continue;
                ways[b | (1 << A[j])][j] += ways[b][i];
            }
        }
    }
}

int main() {
    FASTIO();

    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) {
        cin >> A[i]; A[i]--;
        ways[1<<A[i]][i]++;
    }

    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        adj[a].PB(b);
        adj[b].PB(a);
    }

    for(int b = 1; b < k; b++) transit(b);

    ll ans = 0;
    for(int b = 0; b < (1<<k); b++) {
        for(int i = 0; i < n; i++) {
            ans += ways[b][i];
        }
    }
    cout << ans-n << "\n";

    return 0;
}

/*



*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7392 KB Output is correct
6 Correct 4 ms 7440 KB Output is correct
7 Correct 4 ms 7416 KB Output is correct
8 Correct 4 ms 7508 KB Output is correct
9 Correct 3 ms 7392 KB Output is correct
10 Correct 4 ms 7388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 14168 KB Output is correct
2 Correct 77 ms 13316 KB Output is correct
3 Correct 308 ms 37812 KB Output is correct
4 Correct 93 ms 15980 KB Output is correct
5 Correct 82 ms 15568 KB Output is correct
6 Correct 210 ms 30352 KB Output is correct
7 Correct 309 ms 37852 KB Output is correct
8 Correct 334 ms 38492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 4 ms 7508 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7392 KB Output is correct
6 Correct 4 ms 7440 KB Output is correct
7 Correct 4 ms 7416 KB Output is correct
8 Correct 4 ms 7508 KB Output is correct
9 Correct 3 ms 7392 KB Output is correct
10 Correct 4 ms 7388 KB Output is correct
11 Correct 103 ms 14168 KB Output is correct
12 Correct 77 ms 13316 KB Output is correct
13 Correct 308 ms 37812 KB Output is correct
14 Correct 93 ms 15980 KB Output is correct
15 Correct 82 ms 15568 KB Output is correct
16 Correct 210 ms 30352 KB Output is correct
17 Correct 309 ms 37852 KB Output is correct
18 Correct 334 ms 38492 KB Output is correct
19 Correct 92 ms 14156 KB Output is correct
20 Correct 78 ms 13304 KB Output is correct
21 Correct 323 ms 37800 KB Output is correct
22 Correct 89 ms 15996 KB Output is correct
23 Correct 73 ms 15440 KB Output is correct
24 Correct 220 ms 30320 KB Output is correct
25 Correct 340 ms 37916 KB Output is correct
26 Correct 308 ms 38488 KB Output is correct
27 Correct 145 ms 13456 KB Output is correct
28 Correct 176 ms 15652 KB Output is correct
29 Correct 544 ms 56592 KB Output is correct
30 Correct 322 ms 35464 KB Output is correct
31 Correct 341 ms 34376 KB Output is correct
32 Correct 543 ms 56676 KB Output is correct
33 Correct 4 ms 7508 KB Output is correct
34 Correct 4 ms 7508 KB Output is correct
35 Correct 4 ms 7388 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 4 ms 7376 KB Output is correct
38 Correct 4 ms 7508 KB Output is correct
39 Correct 4 ms 7508 KB Output is correct
40 Correct 4 ms 7508 KB Output is correct
41 Correct 4 ms 7384 KB Output is correct
42 Correct 4 ms 7384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7508 KB Output is correct
2 Correct 120 ms 9500 KB Output is correct
3 Correct 36 ms 9268 KB Output is correct
4 Correct 71 ms 17404 KB Output is correct
5 Correct 56 ms 18112 KB Output is correct
6 Correct 254 ms 36372 KB Output is correct
7 Correct 49 ms 9308 KB Output is correct
8 Correct 108 ms 23732 KB Output is correct
9 Correct 82 ms 24412 KB Output is correct
10 Correct 117 ms 23768 KB Output is correct
11 Correct 145 ms 22828 KB Output is correct
12 Correct 143 ms 28400 KB Output is correct
13 Correct 153 ms 21836 KB Output is correct
14 Correct 240 ms 36392 KB Output is correct
15 Correct 246 ms 36380 KB Output is correct
16 Correct 4 ms 7508 KB Output is correct
17 Correct 4 ms 7508 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7508 KB Output is correct
21 Correct 5 ms 7508 KB Output is correct
22 Correct 4 ms 7516 KB Output is correct
23 Correct 4 ms 7636 KB Output is correct
24 Correct 3 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct