답안 #441082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441082 2021-07-04T06:24:01 Z BeanZ Paths (BOI18_paths) C++14
100 / 100
642 ms 187252 KB
// I_Love_LPL 11m
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 3e5 + 5;
long long mod = 998244353;
const int lim = 4e5 + 5;
const int lg = 22;
const int base = 311;
const long double eps = 1e-6;
ll dp[N][(2 << 5) + 5], c[N];
vector<ll> node[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 1; i <= m; i++){
        ll u, v;
        cin >> u >> v;
        node[u].push_back(v);
        node[v].push_back(u);
    }
    for (int i = 1; i <= n; i++){
        dp[i][(1 << (c[i] - 1))] = 1;
    }
    ll ans = 0;
    for (int i = 0; i < (1 << k); i++){
        for (int g = 1; g <= n; g++){
            if (i & (1 << (c[g] - 1))){
                for (auto d : node[g]){
                    dp[g][i] += dp[d][i ^ (1 << (c[g] - 1))];
                }
            }
            ans = ans + dp[g][i];
        }
    }
    cout << ans - n;
}
/*
Ans:

Out:
*/

Compilation message

paths.cpp: In function 'int main()':
paths.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
paths.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7292 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 5 ms 7272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 17220 KB Output is correct
2 Correct 70 ms 14788 KB Output is correct
3 Correct 453 ms 185968 KB Output is correct
4 Correct 144 ms 35304 KB Output is correct
5 Correct 133 ms 35172 KB Output is correct
6 Correct 329 ms 129848 KB Output is correct
7 Correct 476 ms 186820 KB Output is correct
8 Correct 486 ms 187220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7372 KB Output is correct
2 Correct 5 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7292 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 5 ms 7372 KB Output is correct
9 Correct 4 ms 7372 KB Output is correct
10 Correct 5 ms 7272 KB Output is correct
11 Correct 87 ms 17220 KB Output is correct
12 Correct 70 ms 14788 KB Output is correct
13 Correct 453 ms 185968 KB Output is correct
14 Correct 144 ms 35304 KB Output is correct
15 Correct 133 ms 35172 KB Output is correct
16 Correct 329 ms 129848 KB Output is correct
17 Correct 476 ms 186820 KB Output is correct
18 Correct 486 ms 187220 KB Output is correct
19 Correct 86 ms 20092 KB Output is correct
20 Correct 77 ms 17108 KB Output is correct
21 Correct 457 ms 186740 KB Output is correct
22 Correct 148 ms 35224 KB Output is correct
23 Correct 136 ms 35252 KB Output is correct
24 Correct 325 ms 129908 KB Output is correct
25 Correct 474 ms 186732 KB Output is correct
26 Correct 488 ms 187252 KB Output is correct
27 Correct 74 ms 17100 KB Output is correct
28 Correct 119 ms 23152 KB Output is correct
29 Correct 642 ms 186864 KB Output is correct
30 Correct 406 ms 102320 KB Output is correct
31 Correct 413 ms 102372 KB Output is correct
32 Correct 620 ms 186756 KB Output is correct
33 Correct 5 ms 7372 KB Output is correct
34 Correct 5 ms 7372 KB Output is correct
35 Correct 5 ms 7368 KB Output is correct
36 Correct 5 ms 7372 KB Output is correct
37 Correct 5 ms 7372 KB Output is correct
38 Correct 5 ms 7364 KB Output is correct
39 Correct 5 ms 7368 KB Output is correct
40 Correct 5 ms 7400 KB Output is correct
41 Correct 5 ms 7384 KB Output is correct
42 Correct 5 ms 7244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 29 ms 9812 KB Output is correct
3 Correct 25 ms 9756 KB Output is correct
4 Correct 119 ms 65540 KB Output is correct
5 Correct 96 ms 66036 KB Output is correct
6 Correct 267 ms 65624 KB Output is correct
7 Correct 27 ms 9784 KB Output is correct
8 Correct 172 ms 65620 KB Output is correct
9 Correct 125 ms 66060 KB Output is correct
10 Correct 149 ms 65700 KB Output is correct
11 Correct 133 ms 37284 KB Output is correct
12 Correct 148 ms 51508 KB Output is correct
13 Correct 147 ms 37484 KB Output is correct
14 Correct 270 ms 65664 KB Output is correct
15 Correct 281 ms 65744 KB Output is correct
16 Correct 5 ms 7276 KB Output is correct
17 Correct 5 ms 7372 KB Output is correct
18 Correct 5 ms 7360 KB Output is correct
19 Correct 5 ms 7372 KB Output is correct
20 Correct 5 ms 7372 KB Output is correct
21 Correct 5 ms 7372 KB Output is correct
22 Correct 5 ms 7372 KB Output is correct
23 Correct 5 ms 7372 KB Output is correct
24 Correct 5 ms 7372 KB Output is correct
25 Correct 5 ms 7244 KB Output is correct