답안 #731646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731646 2023-04-27T17:44:26 Z NintsiChkhaidze Paths (BOI18_paths) C++17
100 / 100
339 ms 56660 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int N = 3e5 + 5;
ll dp[37][N];
int c[N];
vector <int> v[N];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	
	int n,m,k;
	cin>>n>>m>>k;
	
	for (int i = 1; i <= n; i++){
		cin>>c[i];
		--c[i];
		dp[(1<<c[i])][i] = 1;
	}
	for (int i = 1; i <= m; i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	
	for (int mask = 0; mask < (1<<k); mask++){
		for (int i = 1; i <= n; i++){
			if (dp[mask][i] && (mask & (1<<c[i])) > 0) {
				for (int to: v[i]){
					if (!(mask & (1<<c[to]))){
						dp[mask ^ (1<<c[to])][to] += dp[mask][i];
					}
				}
			}
		}
	}
	
	ll ans=0;
	for (int i = 1; i <= n; i++){
		for (int mask = 0; mask < (1<<k); mask++){
			if ((mask & (1<<c[i])) > 0 && __builtin_popcount(mask) > 1)
				ans += dp[mask][i];
		}
	}
	cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 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 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7508 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 11336 KB Output is correct
2 Correct 58 ms 10956 KB Output is correct
3 Correct 249 ms 37012 KB Output is correct
4 Correct 91 ms 15900 KB Output is correct
5 Correct 80 ms 15408 KB Output is correct
6 Correct 186 ms 30284 KB Output is correct
7 Correct 238 ms 37772 KB Output is correct
8 Correct 263 ms 38472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 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 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7508 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 69 ms 11336 KB Output is correct
12 Correct 58 ms 10956 KB Output is correct
13 Correct 249 ms 37012 KB Output is correct
14 Correct 91 ms 15900 KB Output is correct
15 Correct 80 ms 15408 KB Output is correct
16 Correct 186 ms 30284 KB Output is correct
17 Correct 238 ms 37772 KB Output is correct
18 Correct 263 ms 38472 KB Output is correct
19 Correct 74 ms 14168 KB Output is correct
20 Correct 60 ms 13272 KB Output is correct
21 Correct 258 ms 37776 KB Output is correct
22 Correct 100 ms 15948 KB Output is correct
23 Correct 83 ms 15532 KB Output is correct
24 Correct 190 ms 30240 KB Output is correct
25 Correct 288 ms 37928 KB Output is correct
26 Correct 241 ms 38432 KB Output is correct
27 Correct 75 ms 13328 KB Output is correct
28 Correct 95 ms 15608 KB Output is correct
29 Correct 337 ms 56608 KB Output is correct
30 Correct 235 ms 35492 KB Output is correct
31 Correct 227 ms 33120 KB Output is correct
32 Correct 339 ms 56660 KB Output is correct
33 Correct 4 ms 7380 KB Output is correct
34 Correct 4 ms 7508 KB Output is correct
35 Correct 4 ms 7380 KB Output is correct
36 Correct 4 ms 7380 KB Output is correct
37 Correct 4 ms 7380 KB Output is correct
38 Correct 4 ms 7420 KB Output is correct
39 Correct 4 ms 7500 KB Output is correct
40 Correct 5 ms 7508 KB Output is correct
41 Correct 5 ms 7448 KB Output is correct
42 Correct 5 ms 7332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 38 ms 8772 KB Output is correct
3 Correct 20 ms 8532 KB Output is correct
4 Correct 59 ms 16076 KB Output is correct
5 Correct 46 ms 16028 KB Output is correct
6 Correct 94 ms 34992 KB Output is correct
7 Correct 26 ms 8544 KB Output is correct
8 Correct 80 ms 22392 KB Output is correct
9 Correct 58 ms 19168 KB Output is correct
10 Correct 74 ms 18268 KB Output is correct
11 Correct 66 ms 21764 KB Output is correct
12 Correct 56 ms 17632 KB Output is correct
13 Correct 67 ms 18212 KB Output is correct
14 Correct 119 ms 35000 KB Output is correct
15 Correct 96 ms 35020 KB Output is correct
16 Correct 4 ms 7380 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 3 ms 7380 KB Output is correct
21 Correct 4 ms 7496 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7388 KB Output is correct
24 Correct 4 ms 7440 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct