답안 #792706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792706 2023-07-25T08:11:56 Z TheSahib Paths (BOI18_paths) C++17
100 / 100
418 ms 97072 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 3e5 + 5;

int n, m, k; 
int color[MAX];
vector<int> g[MAX];

ll dp[MAX][1 << 5];

void solve(){
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> color[i];
        color[i]--;
        dp[i][1 << color[i]] = 1;
    }
    for (int i = 0; i < m; i++)
    {
        int u, v; cin >> u >> v;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    ll ans = 0;
    for (int mask = 1; mask < (1 << k); mask++)
    {
        if(__popcount(mask) <= 1) continue;
        for (int node = 1; node <= n; node++)
        {
            if(!(mask & (1 << color[node]))) continue;
            for(int to:g[node]){
                dp[node][mask] += dp[to][mask ^ (1 << color[node])];
            }
            ans += dp[node][mask];
        }
    }
    cout << ans << '\n';
}

int main()
{
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 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 7380 KB Output is correct
5 Correct 4 ms 7360 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 3 ms 7360 KB Output is correct
10 Correct 3 ms 7360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 14988 KB Output is correct
2 Correct 97 ms 13396 KB Output is correct
3 Correct 312 ms 96508 KB Output is correct
4 Correct 156 ms 22732 KB Output is correct
5 Correct 146 ms 22760 KB Output is correct
6 Correct 246 ms 69368 KB Output is correct
7 Correct 316 ms 96436 KB Output is correct
8 Correct 334 ms 97040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7252 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 7380 KB Output is correct
5 Correct 4 ms 7360 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 3 ms 7360 KB Output is correct
10 Correct 3 ms 7360 KB Output is correct
11 Correct 116 ms 14988 KB Output is correct
12 Correct 97 ms 13396 KB Output is correct
13 Correct 312 ms 96508 KB Output is correct
14 Correct 156 ms 22732 KB Output is correct
15 Correct 146 ms 22760 KB Output is correct
16 Correct 246 ms 69368 KB Output is correct
17 Correct 316 ms 96436 KB Output is correct
18 Correct 334 ms 97040 KB Output is correct
19 Correct 118 ms 15008 KB Output is correct
20 Correct 95 ms 13296 KB Output is correct
21 Correct 327 ms 96508 KB Output is correct
22 Correct 145 ms 22756 KB Output is correct
23 Correct 154 ms 22752 KB Output is correct
24 Correct 257 ms 69384 KB Output is correct
25 Correct 314 ms 96436 KB Output is correct
26 Correct 319 ms 97072 KB Output is correct
27 Correct 98 ms 13400 KB Output is correct
28 Correct 124 ms 16588 KB Output is correct
29 Correct 418 ms 96584 KB Output is correct
30 Correct 288 ms 55364 KB Output is correct
31 Correct 304 ms 55264 KB Output is correct
32 Correct 417 ms 96508 KB Output is correct
33 Correct 4 ms 7252 KB Output is correct
34 Correct 3 ms 7380 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 5 ms 7380 KB Output is correct
38 Correct 3 ms 7356 KB Output is correct
39 Correct 3 ms 7380 KB Output is correct
40 Correct 3 ms 7380 KB Output is correct
41 Correct 3 ms 7364 KB Output is correct
42 Correct 3 ms 7360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 37 ms 9216 KB Output is correct
3 Correct 42 ms 9272 KB Output is correct
4 Correct 115 ms 36916 KB Output is correct
5 Correct 83 ms 37572 KB Output is correct
6 Correct 206 ms 36912 KB Output is correct
7 Correct 51 ms 9284 KB Output is correct
8 Correct 177 ms 36920 KB Output is correct
9 Correct 103 ms 37676 KB Output is correct
10 Correct 176 ms 37664 KB Output is correct
11 Correct 155 ms 23036 KB Output is correct
12 Correct 113 ms 30416 KB Output is correct
13 Correct 158 ms 23140 KB Output is correct
14 Correct 228 ms 36920 KB Output is correct
15 Correct 164 ms 36932 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 3 ms 7380 KB Output is correct
18 Correct 5 ms 7252 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
20 Correct 4 ms 7264 KB Output is correct
21 Correct 4 ms 7380 KB Output is correct
22 Correct 4 ms 7360 KB Output is correct
23 Correct 4 ms 7356 KB Output is correct
24 Correct 4 ms 7252 KB Output is correct
25 Correct 4 ms 7252 KB Output is correct