Submission #897748

# Submission time Handle Problem Language Result Execution time Memory
897748 2024-01-03T15:58:11 Z LCJLY Paths (BOI18_paths) C++14
100 / 100
269 ms 107580 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;

int n,m,k;
int arr[300005];
vector<int>adj[300005];
int memo[300005][35];

int dp(int index, int mask){
	if(memo[index][mask]!=-1) return memo[index][mask];
	int ans=0;
	if(__builtin_popcount(mask)>1) ans=1;
	
	for(auto it:adj[index]){
		if(mask&(1<<arr[it])) continue;
		int next=mask|(1<<arr[it]);
		ans+=dp(it,next);
	}
	return memo[index][mask]=ans;
}

void solve(){	
	cin >> n >> m >> k;
	
	for(int x=1;x<=n;x++){
		cin >> arr[x];
		arr[x]--;
	}
	
	int temp,temp2;
	for(int x=0;x<m;x++){
		cin >> temp >> temp2;
		adj[temp].push_back(temp2);
		adj[temp2].push_back(temp);
	}
	
	memset(memo,-1,sizeof(memo));
	int counter=0;
	for(int x=1;x<=n;x++){
		counter+=dp(x,1<<arr[x]);
	}
	cout << counter;
}
 
int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	//freopen("redistricting.in", "r", stdin);
	//freopen("redistricting.out", "w", stdout);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 90712 KB Output is correct
2 Correct 13 ms 90716 KB Output is correct
3 Correct 11 ms 90712 KB Output is correct
4 Correct 13 ms 90968 KB Output is correct
5 Correct 11 ms 90716 KB Output is correct
6 Correct 11 ms 90716 KB Output is correct
7 Correct 12 ms 90716 KB Output is correct
8 Correct 12 ms 90716 KB Output is correct
9 Correct 12 ms 90784 KB Output is correct
10 Correct 11 ms 90716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 100924 KB Output is correct
2 Correct 53 ms 100228 KB Output is correct
3 Correct 220 ms 106956 KB Output is correct
4 Correct 78 ms 102412 KB Output is correct
5 Correct 78 ms 102168 KB Output is correct
6 Correct 160 ms 104128 KB Output is correct
7 Correct 268 ms 106836 KB Output is correct
8 Correct 207 ms 107348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 90712 KB Output is correct
2 Correct 13 ms 90716 KB Output is correct
3 Correct 11 ms 90712 KB Output is correct
4 Correct 13 ms 90968 KB Output is correct
5 Correct 11 ms 90716 KB Output is correct
6 Correct 11 ms 90716 KB Output is correct
7 Correct 12 ms 90716 KB Output is correct
8 Correct 12 ms 90716 KB Output is correct
9 Correct 12 ms 90784 KB Output is correct
10 Correct 11 ms 90716 KB Output is correct
11 Correct 63 ms 100924 KB Output is correct
12 Correct 53 ms 100228 KB Output is correct
13 Correct 220 ms 106956 KB Output is correct
14 Correct 78 ms 102412 KB Output is correct
15 Correct 78 ms 102168 KB Output is correct
16 Correct 160 ms 104128 KB Output is correct
17 Correct 268 ms 106836 KB Output is correct
18 Correct 207 ms 107348 KB Output is correct
19 Correct 62 ms 100688 KB Output is correct
20 Correct 57 ms 100572 KB Output is correct
21 Correct 225 ms 107028 KB Output is correct
22 Correct 82 ms 102228 KB Output is correct
23 Correct 72 ms 102224 KB Output is correct
24 Correct 153 ms 104184 KB Output is correct
25 Correct 228 ms 107036 KB Output is correct
26 Correct 206 ms 107580 KB Output is correct
27 Correct 64 ms 100472 KB Output is correct
28 Correct 82 ms 102384 KB Output is correct
29 Correct 262 ms 106836 KB Output is correct
30 Correct 214 ms 103620 KB Output is correct
31 Correct 244 ms 103664 KB Output is correct
32 Correct 269 ms 106960 KB Output is correct
33 Correct 12 ms 90716 KB Output is correct
34 Correct 11 ms 90716 KB Output is correct
35 Correct 12 ms 90716 KB Output is correct
36 Correct 12 ms 90808 KB Output is correct
37 Correct 12 ms 90716 KB Output is correct
38 Correct 12 ms 90848 KB Output is correct
39 Correct 12 ms 90716 KB Output is correct
40 Correct 11 ms 90856 KB Output is correct
41 Correct 11 ms 90716 KB Output is correct
42 Correct 12 ms 90912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 90716 KB Output is correct
2 Correct 36 ms 93788 KB Output is correct
3 Correct 25 ms 93780 KB Output is correct
4 Correct 68 ms 95828 KB Output is correct
5 Correct 48 ms 95944 KB Output is correct
6 Correct 76 ms 95780 KB Output is correct
7 Correct 29 ms 93652 KB Output is correct
8 Correct 71 ms 95780 KB Output is correct
9 Correct 57 ms 96188 KB Output is correct
10 Correct 84 ms 95944 KB Output is correct
11 Correct 64 ms 94668 KB Output is correct
12 Correct 60 ms 95296 KB Output is correct
13 Correct 78 ms 94804 KB Output is correct
14 Correct 92 ms 95568 KB Output is correct
15 Correct 71 ms 95828 KB Output is correct
16 Correct 11 ms 90712 KB Output is correct
17 Correct 13 ms 90712 KB Output is correct
18 Correct 11 ms 90716 KB Output is correct
19 Correct 11 ms 90856 KB Output is correct
20 Correct 11 ms 90880 KB Output is correct
21 Correct 12 ms 90712 KB Output is correct
22 Correct 12 ms 90716 KB Output is correct
23 Correct 11 ms 90716 KB Output is correct
24 Correct 12 ms 90716 KB Output is correct
25 Correct 12 ms 90716 KB Output is correct