Submission #566900

# Submission time Handle Problem Language Result Execution time Memory
566900 2022-05-23T05:50:05 Z inluminas Paths (BOI18_paths) C++17
100 / 100
360 ms 58936 KB
#include"bits/stdc++.h"
using namespace std;

#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX
#define l first
#define r second

const int lmt=3e5+10;
vector<int>adj[lmt];

int main(){
	fastio;

	int n,m,k;
	cin>>n>>m>>k;
	ll dp[n+1][(1<<k)];
	int col[n+1];
	for(int i=1;i<=n;i++) cin>>col[i];

	vector<int>T[k+1];
	
	for(int i=0;i<(1<<k);i++){
		int cnt=__builtin_popcount(i);
		T[cnt].push_back(i);
	}

	for(int i=1;i<=m;i++){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for(int i=1;i<=n;i++){
		for(int j=0;j<(1<<k);j++) dp[i][j]=0;
	}

	for(int i=1;i<=n;i++){
		dp[i][(1<<(col[i]-1))]=1;
	}

	ll ans=0;

	for(int j=2;j<=k;j++){
		for(int i=1;i<=n;i++){
			for(int v:adj[i]){
				for(int val:T[j-1]){
					if(val&(1<<(col[i]-1))) continue;
					dp[i][val|(1<<(col[i]-1))]+=dp[v][val];
				}
			}
		}
	}

	for(int i=1;i<=n;i++){
		for(int j=2;j<=k;j++){
			for(int val:T[j]){
				ans+=dp[i][val];
			}
		}
	}

	cout<<ans<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 6 ms 7360 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 6 ms 7252 KB Output is correct
8 Correct 4 ms 7368 KB Output is correct
9 Correct 4 ms 7340 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 14148 KB Output is correct
2 Correct 62 ms 13232 KB Output is correct
3 Correct 283 ms 40104 KB Output is correct
4 Correct 112 ms 16196 KB Output is correct
5 Correct 116 ms 15716 KB Output is correct
6 Correct 227 ms 31836 KB Output is correct
7 Correct 277 ms 40144 KB Output is correct
8 Correct 258 ms 40736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7252 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 6 ms 7360 KB Output is correct
4 Correct 4 ms 7252 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 6 ms 7252 KB Output is correct
8 Correct 4 ms 7368 KB Output is correct
9 Correct 4 ms 7340 KB Output is correct
10 Correct 5 ms 7252 KB Output is correct
11 Correct 108 ms 14148 KB Output is correct
12 Correct 62 ms 13232 KB Output is correct
13 Correct 283 ms 40104 KB Output is correct
14 Correct 112 ms 16196 KB Output is correct
15 Correct 116 ms 15716 KB Output is correct
16 Correct 227 ms 31836 KB Output is correct
17 Correct 277 ms 40144 KB Output is correct
18 Correct 258 ms 40736 KB Output is correct
19 Correct 75 ms 14048 KB Output is correct
20 Correct 63 ms 13172 KB Output is correct
21 Correct 311 ms 40148 KB Output is correct
22 Correct 104 ms 16184 KB Output is correct
23 Correct 127 ms 15740 KB Output is correct
24 Correct 206 ms 31788 KB Output is correct
25 Correct 261 ms 40152 KB Output is correct
26 Correct 265 ms 40844 KB Output is correct
27 Correct 71 ms 13240 KB Output is correct
28 Correct 90 ms 15616 KB Output is correct
29 Correct 306 ms 58932 KB Output is correct
30 Correct 256 ms 36512 KB Output is correct
31 Correct 241 ms 36588 KB Output is correct
32 Correct 360 ms 58936 KB Output is correct
33 Correct 4 ms 7252 KB Output is correct
34 Correct 4 ms 7380 KB Output is correct
35 Correct 4 ms 7252 KB Output is correct
36 Correct 4 ms 7252 KB Output is correct
37 Correct 5 ms 7368 KB Output is correct
38 Correct 4 ms 7368 KB Output is correct
39 Correct 4 ms 7360 KB Output is correct
40 Correct 6 ms 7380 KB Output is correct
41 Correct 5 ms 7368 KB Output is correct
42 Correct 4 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 35 ms 9416 KB Output is correct
3 Correct 26 ms 9212 KB Output is correct
4 Correct 79 ms 18140 KB Output is correct
5 Correct 67 ms 18852 KB Output is correct
6 Correct 134 ms 36812 KB Output is correct
7 Correct 34 ms 9260 KB Output is correct
8 Correct 90 ms 24396 KB Output is correct
9 Correct 73 ms 25028 KB Output is correct
10 Correct 79 ms 25168 KB Output is correct
11 Correct 76 ms 22944 KB Output is correct
12 Correct 82 ms 30404 KB Output is correct
13 Correct 84 ms 23244 KB Output is correct
14 Correct 124 ms 36932 KB Output is correct
15 Correct 119 ms 37068 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 5 ms 7328 KB Output is correct
18 Correct 4 ms 7368 KB Output is correct
19 Correct 4 ms 7252 KB Output is correct
20 Correct 4 ms 7368 KB Output is correct
21 Correct 4 ms 7252 KB Output is correct
22 Correct 4 ms 7252 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 5 ms 7320 KB Output is correct
25 Correct 4 ms 7252 KB Output is correct