Submission #1132031

#TimeUsernameProblemLanguageResultExecution timeMemory
1132031ByeWorldPaths (BOI18_paths)C++20
100 / 100
501 ms103080 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define int long long #define ll long long #define pb push_back #define fi first #define se second #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) #define ld long double using namespace std; typedef pair<int,int> pii; typedef pair<char,char> pcc; typedef pair<int,pii> ipii; typedef pair<pii,pii> ipiii; const int MAXN = 3e5+10; const int MAXA = 1e6; const int MOD = 1e9+7; const int INF = 1e9+10; const int LOG = 21; const ld EPS = 1e-12; int n, m, k, c[MAXN], num[MAXN][35]; vector <int> adj[MAXN]; signed main(){ // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>m>>k; for(int i=1; i<=n; i++){ cin>>c[i]; c[i]--; num[i][ (1<<c[i]) ] = 1; } for(int i=1;i<=m; i++){ int x,y; cin>>x>>y; adj [x].pb(y); adj[y].pb(x); } for(int p=2; p<=k; p++){ for(int nw=1; nw<=n; nw++){ for(auto nx : adj[nw]){ for(int i=1; i<(1<<k); i++){ if( !((i>>c[nw])&1) ) continue; if(__builtin_popcount(i) != p) continue; num[nw][i] += num[nx][i ^ (1<<c[nw])]; } } } } int ans = 0; for(int nw=1; nw<=n; nw++){ // cout << nw << "nw\n"; for(int j=1; j<(1<<k); j++){ if(__builtin_popcount(j) == 1) continue; ans += num[nw][j]; // cout << j << ' '<< num[nw][j] << " pp\n"; } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...