Submission #226974

#TimeUsernameProblemLanguageResultExecution timeMemory
226974anubhavdharPaths (BOI18_paths)C++14
100 / 100
576 ms55800 KiB
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define FOR(i,n) for(i=0;i<(n);++i) #define FORe(i,n) for(i=1;i<=(n);++i) #define FORr(i,a,b) for(i=(a);i<(b);++i) #define FORrev(i,n) for(i=(n);i>=0;--i) #define ii pair<ll,ll> #define vi vector<ll> #define vii vector<ii> #define ff first #define ss second #define cd complex<double> #define vcd vector<cd> #define ldd long double #define all(x) (x).begin(),(x).end() using namespace std; const short int __PRECISION = 10; const ll MOD = 1e9+7; const ll INF = 1e17 + 1101; const ll LOGN = 17; const ll MAXN = 2e5+5; const ll ROOTN = 320; const ldd PI = acos(-1); const ldd EPS = 1e-7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N,M,K; int i,j,k,mask; ll ans = 0; cin>>N>>M>>K; vi g[N+1]; ll dp[N+1][(1<<K)],col[N+1]; for(i = 1; i <= N; ++i) { cin>>j; col[i] = j-1; } for(i = 0; i < M; ++i) { cin>>j>>k; if(col[j] != col[k]) { g[j].pb(k); g[k].pb(j); } } for(i = 0; i <= N; ++i) for(mask = 0; mask < (1<<K); ++mask) dp[i][mask] = 0; for(i = 1; i <= N; ++i) dp[i][(1<<col[i])] = 1; for(mask = 0; mask < (1<<K); ++mask) for(i = 1; i <= N; ++i) if(mask&(1<<col[i])) for(ll b : g[i]) if(((1<<col[b])&(mask)) == 0) dp[b][(mask | (1<<col[b]))] += dp[i][mask]; for(i = 1; i <= N; ++i) for(mask = 0; mask < (1<<K); ++mask) if(__builtin_popcount(mask) > 1) ans += dp[i][mask]; cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...