제출 #1274555

#제출 시각아이디문제언어결과실행 시간메모리
1274555DanielPr8Paths (BOI18_paths)C++20
100 / 100
422 ms107796 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using pll = pair<ll,ll>; using vpl = vector<pll>; using vvl =vector<vll>; #define f first #define s second #define pb push_back #define all(v) v.begin(),v.end() int main(){ ios_base::sync_with_stdio(0);cin.tie(NULL); ll n, m ,k; cin >> n >> m >> k; vll cl(n); for(ll& i:cl){cin >> i;i--;} vvl g(n); for(ll a, b, i=0; i < m; ++i){ cin >> a >> b; g[--a].pb(--b); g[b].pb(a); } vvl dp(n, vll(32)); vll ord(31); iota(all(ord),1); sort(all(ord), [&](ll a, ll b){return __builtin_popcount(a)<__builtin_popcount(b);}); for(ll i = 0; i < n; ++i)dp[i][1<<cl[i]]=1; ll ans = 0; for(ll i: ord){ for(ll j = 0; j < n; ++j){ if(__builtin_popcount(i)>1)ans += dp[j][i]; if(i & (1<<cl[j])){ for(ll h: g[j]){ if(i & (1<<cl[h]))continue; dp[h][i|(1<<cl[h])]+=dp[j][i]; } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...