Submission #716044

#TimeUsernameProblemLanguageResultExecution timeMemory
716044Charizard2021Paths (BOI18_paths)C++17
100 / 100
594 ms26700 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m >> k; int colors[n]; for(int i = 0; i < n; i++){ cin >> colors[i]; colors[i]--; } vector<int> adj[n]; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--; b--; adj[a].push_back(b); adj[b].push_back(a); } vector<int> order(k); for(int i = 0; i < k; i++){ order[i] = i; } long long res = 0; vector<long long> dp(n); vector<long long> next(n); do { for(int i = 0; i < n; i++){ if(colors[i] == order[0]){ dp[i] = 1; } else{ dp[i] = 0; } } for(int i = 1; i < k; i++){ for(int j = 0; j < n; j++){ long long x = 0; if(colors[j] == order[i]){ for(int y : adj[j]){ x += dp[y]; } } next[j] = x; } swap(dp, next); if(is_sorted(order.begin() + i + 1, order.end())){ for(int j = 0; j < n; j++){ res += dp[j]; } } } } while (next_permutation(order.begin(), order.end())); 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...