Submission #473369

# Submission time Handle Problem Language Result Execution time Memory
473369 2021-09-15T12:51:30 Z fadi57 Paths (BOI18_paths) C++14
0 / 100
212 ms 22480 KB
#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+10;
typedef long long ll;

 int mod=1e9+7;
const int MXm=22;
#define F first
#define S second
const int inf=1e9+10;

 ll dp[mx][5<<1];int c[mx];
 vector<int>adj[mx];
 int n,m,k;
  ll solve(int node,int mask){

  ll &ret=dp[node][mask];


  if(ret!=-1){

    return ret;
  }
 ret=1;

   for(auto it:adj[node]){
    if(!((1<<c[it])&mask)){

        ret+=solve(it,mask|(1<<c[it]));
    }
   }
 return ret;


  }
  int main(){
    memset(dp,-1,sizeof(dp));
    cin>>n>>m>>k;

    for(int i=1;i<=n;i++){
        cin>>c[i];
        c[i]--;
    }
  ll ans=0;
      for(int i=1;i<=m;i++){
       int a,b;cin>>a>>b;
       adj[a].push_back(b);
       adj[b].push_back(a);
      }
    for(int i=1;i<=n;i++){
        ans+=solve(i,1<<c[i]);
    }
  cout<<ans-n;

      }
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 10444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 212 ms 14012 KB Output is correct
2 Correct 178 ms 16192 KB Output is correct
3 Runtime error 71 ms 22480 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 10444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10404 KB Output is correct
2 Incorrect 74 ms 11532 KB Output isn't correct
3 Halted 0 ms 0 KB -