// #pragma GCC optimize("Ofast,unroll-loops")
// el psy congroo
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
const int mod = LLONG_MAX, sze = 3e5+23, inf = INT_MAX, LG = 19,pr = 31;
vector<int> graph[sze];
int used[sze];
int var[6][6][6][6][6];
vector<int> ord;
int col[sze];
int dp[sze];
int nxt[sze];
void dfs(int node,int idx){
if(used[node]){
return;
}
used[node]=1;
if(idx== (ord.size()-1 )){
dp[node]=1;
return;
}
dp[node]=0;
for(auto v:graph[node]){
if(col[v]==ord[idx+1]){
dfs(v,idx+1);
dp[node]=(dp[node]+ dp[v])%mod;
}
}
}
vector<int> co[10];
void fast(){
int n,m,k;
cin>>n>>m>>k;
for(int i =1;i<=n;i++){
cin>>col[i];
co[col[i]].pb(i);
}
int u,v;
for(int i =0;i<m;i++){
cin>>u>>v;
graph[u].pb(v);
graph[v].pb(u);
}
int ans=0;
vector<int> ad;
for(int i =0;i<k;i++){
ad.pb(i+1);
}
int hash=0,pp;
// for(auto v:ad) cout<<v<<" ";cout<<endl;
do{
ord.clear();
vector<int> cc(5,0);
ord.pb(ad[0]);
cc[0]=ord[0];
for(int i =1;i<k;i++){
ord.pb(ad[i]);
cc[i]=ord[i];
if( !var[cc[0]][cc[1]][cc[2]][cc[3]][cc[4]] ){
// for(auto v:ord) cout<<v<<" ,";cout<<endl;
for(int j=1;j<=n;j++){
dp[j]=0;
used[j]=0 ;
}
for(auto v:co[ord[0]]){
dfs(v,0);
if(dp[v]){
// cout<<v<<" == "<<dp[v]<<endl;
ans=(ans+dp[v])%mod;
}
}
var[cc[0]][cc[1]][cc[2]][cc[3]][cc[4]]=1;
}
}
}while(next_permutation(all(ad)));
putr(ans);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
fast();
}
return 0;
}
Compilation message
paths.cpp: In function 'void dfs(long long int, long long int)':
paths.cpp:27:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if(idx== (ord.size()-1 )){
| ~~~^~~~~~~~~~~~~~~~~~
paths.cpp: In function 'void fast()':
paths.cpp:60:9: warning: unused variable 'hash' [-Wunused-variable]
60 | int hash=0,pp;
| ^~~~
paths.cpp:60:16: warning: unused variable 'pp' [-Wunused-variable]
60 | int hash=0,pp;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14672 KB |
Output is correct |
2 |
Correct |
3 ms |
14672 KB |
Output is correct |
3 |
Correct |
3 ms |
14672 KB |
Output is correct |
4 |
Correct |
4 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
12624 KB |
Output is correct |
6 |
Correct |
3 ms |
14528 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
4 ms |
14672 KB |
Output is correct |
9 |
Correct |
3 ms |
14672 KB |
Output is correct |
10 |
Correct |
3 ms |
14672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
21936 KB |
Output is correct |
2 |
Correct |
50 ms |
21744 KB |
Output is correct |
3 |
Correct |
202 ms |
27568 KB |
Output is correct |
4 |
Correct |
69 ms |
22988 KB |
Output is correct |
5 |
Correct |
56 ms |
20936 KB |
Output is correct |
6 |
Correct |
136 ms |
25508 KB |
Output is correct |
7 |
Correct |
202 ms |
32056 KB |
Output is correct |
8 |
Correct |
191 ms |
32528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14672 KB |
Output is correct |
2 |
Correct |
3 ms |
14672 KB |
Output is correct |
3 |
Correct |
3 ms |
14672 KB |
Output is correct |
4 |
Correct |
4 ms |
14672 KB |
Output is correct |
5 |
Correct |
3 ms |
12624 KB |
Output is correct |
6 |
Correct |
3 ms |
14528 KB |
Output is correct |
7 |
Correct |
3 ms |
14672 KB |
Output is correct |
8 |
Correct |
4 ms |
14672 KB |
Output is correct |
9 |
Correct |
3 ms |
14672 KB |
Output is correct |
10 |
Correct |
3 ms |
14672 KB |
Output is correct |
11 |
Correct |
59 ms |
21936 KB |
Output is correct |
12 |
Correct |
50 ms |
21744 KB |
Output is correct |
13 |
Correct |
202 ms |
27568 KB |
Output is correct |
14 |
Correct |
69 ms |
22988 KB |
Output is correct |
15 |
Correct |
56 ms |
20936 KB |
Output is correct |
16 |
Correct |
136 ms |
25508 KB |
Output is correct |
17 |
Correct |
202 ms |
32056 KB |
Output is correct |
18 |
Correct |
191 ms |
32528 KB |
Output is correct |
19 |
Correct |
60 ms |
24544 KB |
Output is correct |
20 |
Correct |
54 ms |
23944 KB |
Output is correct |
21 |
Correct |
187 ms |
31928 KB |
Output is correct |
22 |
Correct |
72 ms |
26392 KB |
Output is correct |
23 |
Correct |
76 ms |
24272 KB |
Output is correct |
24 |
Correct |
108 ms |
29720 KB |
Output is correct |
25 |
Correct |
178 ms |
31908 KB |
Output is correct |
26 |
Correct |
172 ms |
32528 KB |
Output is correct |
27 |
Correct |
105 ms |
24152 KB |
Output is correct |
28 |
Correct |
139 ms |
26240 KB |
Output is correct |
29 |
Correct |
465 ms |
32036 KB |
Output is correct |
30 |
Correct |
257 ms |
29324 KB |
Output is correct |
31 |
Correct |
296 ms |
28560 KB |
Output is correct |
32 |
Correct |
553 ms |
31892 KB |
Output is correct |
33 |
Correct |
4 ms |
14672 KB |
Output is correct |
34 |
Correct |
4 ms |
14728 KB |
Output is correct |
35 |
Correct |
4 ms |
14692 KB |
Output is correct |
36 |
Correct |
5 ms |
14928 KB |
Output is correct |
37 |
Correct |
4 ms |
12624 KB |
Output is correct |
38 |
Correct |
4 ms |
14740 KB |
Output is correct |
39 |
Correct |
4 ms |
14728 KB |
Output is correct |
40 |
Correct |
4 ms |
14672 KB |
Output is correct |
41 |
Correct |
3 ms |
14672 KB |
Output is correct |
42 |
Correct |
3 ms |
14672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14672 KB |
Output is correct |
2 |
Correct |
133 ms |
16928 KB |
Output is correct |
3 |
Correct |
20 ms |
17488 KB |
Output is correct |
4 |
Correct |
59 ms |
20152 KB |
Output is correct |
5 |
Correct |
39 ms |
20672 KB |
Output is correct |
6 |
Correct |
346 ms |
20420 KB |
Output is correct |
7 |
Correct |
39 ms |
17656 KB |
Output is correct |
8 |
Correct |
107 ms |
20340 KB |
Output is correct |
9 |
Correct |
55 ms |
20600 KB |
Output is correct |
10 |
Correct |
70 ms |
20380 KB |
Output is correct |
11 |
Correct |
231 ms |
18888 KB |
Output is correct |
12 |
Correct |
131 ms |
19656 KB |
Output is correct |
13 |
Correct |
215 ms |
19140 KB |
Output is correct |
14 |
Correct |
333 ms |
20312 KB |
Output is correct |
15 |
Correct |
278 ms |
20400 KB |
Output is correct |
16 |
Correct |
4 ms |
14672 KB |
Output is correct |
17 |
Correct |
4 ms |
14672 KB |
Output is correct |
18 |
Correct |
4 ms |
14672 KB |
Output is correct |
19 |
Correct |
4 ms |
14672 KB |
Output is correct |
20 |
Correct |
3 ms |
12624 KB |
Output is correct |
21 |
Correct |
4 ms |
14672 KB |
Output is correct |
22 |
Correct |
4 ms |
14720 KB |
Output is correct |
23 |
Correct |
4 ms |
14840 KB |
Output is correct |
24 |
Correct |
4 ms |
14672 KB |
Output is correct |
25 |
Correct |
4 ms |
14672 KB |
Output is correct |