제출 #1127782

#제출 시각아이디문제언어결과실행 시간메모리
1127782nguyenphong233Paths (BOI18_paths)C++20
100 / 100
593 ms79000 KiB
// 23 - 12 - 23 #include<bits/stdc++.h> using namespace std; #define read() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define day() time_t now = time(0);char* x = ctime(&now);cerr<<"Right Now Is : "<<x<<"\n" #define int long long #define ii pair<int,int> #define X first #define Y second const long long MAX = (int)3e5 + 5; const long long INF = (int)1e9; const long long MOD = (int)1e9 + 7; int n,m,k; vector<int> adj[MAX]; int a[MAX]; signed main(){ read(); cin >> n >> m >> k; vector<vector<int>> dp(n + 5,vector<int>((1 << k) + 5,0)); for(int i = 1;i <= n;i++){ cin >> a[i]; a[i]--; dp[i][(1 << a[i])] = 1; } for(int i = 1,u,v;i <= m;i++){ cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for(int j = 1;j <= k;j++){ for(int i = 1;i <= n;i++){ //cout << i << " " << a[i] << "\n"; for(int mask = 0;mask < (1 << k);mask++){ if(__builtin_popcount(mask) != j)continue; if(!(mask >> a[i] & 1))continue; for(auto v : adj[i]){ dp[i][mask] = (dp[i][mask] + dp[v][mask ^ (1 << a[i])]); } //cout << i << " " << mask << " " << dp[i][mask] << "\n"; } } } int res = 0; for(int i = 1;i <= n;i++){ for(int mask = 1;mask < (1 << k);mask++){ if(__builtin_popcount(mask) < 2)continue; res += dp[i][mask]; } } cout << res << "\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...