Submission #718015

# Submission time Handle Problem Language Result Execution time Memory
718015 2023-04-03T07:00:10 Z amirhoseinfar1385 Paths (BOI18_paths) C++17
100 / 100
679 ms 24388 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
vector<int>all,val,unnow;
vector<vector<int>>adj,allv;
long long res=0;

void solve(int mina){
	if(mina>k){
		if((int)unnow.size()<=1){
			return ;
		}
		do{
			for(auto x:unnow){
				for(auto y:allv[x]){
					val[y]=0;
				}
			}
			for(int i=0;i<(int)unnow.size()-1;i++){
				for(auto x:allv[unnow[i]]){
					if(i==0){
						val[x]=1;
					}
					for(auto y:adj[x]){
						if(all[y]==unnow[i+1]){
							val[y]+=val[x];
						}
					}
				}
			}
			for(auto x:allv[unnow.back()]){
				res+=val[x];
			}
		}while(next_permutation(unnow.begin(),unnow.end()));
		return ;
	}
	solve(mina+1);
	unnow.push_back(mina);
	solve(mina+1);
	unnow.pop_back();
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k;
	val.resize(n+1);
	all.resize(n+1);
	adj.resize(n+1);
	allv.resize(k+1);
	for(int i=1;i<=n;i++){
		cin>>all[i];
		allv[all[i]].push_back(i);
	}
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	solve(1);
	cout<<res<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 6888 KB Output is correct
2 Correct 62 ms 6108 KB Output is correct
3 Correct 304 ms 23860 KB Output is correct
4 Correct 90 ms 9160 KB Output is correct
5 Correct 84 ms 9220 KB Output is correct
6 Correct 221 ms 18488 KB Output is correct
7 Correct 284 ms 23640 KB Output is correct
8 Correct 300 ms 24320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 76 ms 6888 KB Output is correct
12 Correct 62 ms 6108 KB Output is correct
13 Correct 304 ms 23860 KB Output is correct
14 Correct 90 ms 9160 KB Output is correct
15 Correct 84 ms 9220 KB Output is correct
16 Correct 221 ms 18488 KB Output is correct
17 Correct 284 ms 23640 KB Output is correct
18 Correct 300 ms 24320 KB Output is correct
19 Correct 92 ms 6960 KB Output is correct
20 Correct 66 ms 6172 KB Output is correct
21 Correct 286 ms 23744 KB Output is correct
22 Correct 105 ms 9124 KB Output is correct
23 Correct 92 ms 9032 KB Output is correct
24 Correct 196 ms 18588 KB Output is correct
25 Correct 276 ms 23840 KB Output is correct
26 Correct 286 ms 24388 KB Output is correct
27 Correct 124 ms 6092 KB Output is correct
28 Correct 178 ms 7760 KB Output is correct
29 Correct 665 ms 23740 KB Output is correct
30 Correct 460 ms 15476 KB Output is correct
31 Correct 495 ms 15604 KB Output is correct
32 Correct 647 ms 23752 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 150 ms 2164 KB Output is correct
3 Correct 24 ms 2196 KB Output is correct
4 Correct 69 ms 7920 KB Output is correct
5 Correct 53 ms 8648 KB Output is correct
6 Correct 657 ms 7924 KB Output is correct
7 Correct 41 ms 2180 KB Output is correct
8 Correct 161 ms 8028 KB Output is correct
9 Correct 141 ms 8784 KB Output is correct
10 Correct 162 ms 8896 KB Output is correct
11 Correct 387 ms 5068 KB Output is correct
12 Correct 400 ms 7108 KB Output is correct
13 Correct 384 ms 5320 KB Output is correct
14 Correct 679 ms 8096 KB Output is correct
15 Correct 606 ms 8256 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct