Submission #108090

#TimeUsernameProblemLanguageResultExecution timeMemory
108090AbelyanPaths (BOI18_paths)C++17
100 / 100
731 ms170304 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define FOR(i,a) for (int i=0;i<(a);++i) #define FORD(i,a) for (int i=(a)-1;i>=0;i--) #define FORT(i,a,b) for (int i=(a);i<=(b);++i) #define FORTD(i,b,a) for (int i=(b);i>=(a);--i) #define trav(i,v) for (auto i : v) #define all(v) v.begin(),v.end() #define ad push_back #define fr first #define sc second #define mpr(a,b) make_pair(a,b) #define pir pair<int,int> #define all(v) v.begin(),v.end() #define make_unique(v) v.erase(unique(all(v),v.end())) #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define dbg(x); #define dbgv(v); #define srng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define y1 EsiHancagorcRepa #ifdef ALEXPC #define dbg(x); cout<<#x<<" = "<<x<<endl #define dbgv(v); cout<<#v<<" = ["; trav(tv,v)cout<<"tv,";cout<<"]"<<endl #endif const int N=3*1e5+6; const ll MOD=1000*1000*1000+7; int f[N]; ll dp[N][65]; vector<int> g[N]; void rec(int v,int mask){ if (dp[v][mask]!=0)return; dp[v][mask]=1; trav(to,g[v]){ if (f[to]&mask)continue; rec(to,mask+f[to]); dp[v][mask]+=dp[to][mask+f[to]]; //cout<<v<<" "<<mask<<" "<<dp[to][ma] } } int main(){ fastio; srng; int n, m, k; cin >> n >> m >> k; FOR(i, n) { cin >> f[i+1]; f[i+1]--; f[i+1]=(1<<f[i+1]); //FOR(j,31)dp[i+1][j]=-1; } FOR(i, m) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } ll ans=0; FORT(i,1,n){ rec(i,f[i]); ans+=dp[i][f[i]]; ans--; } cout<<ans<<endl; 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...