제출 #680572

#제출 시각아이디문제언어결과실행 시간메모리
680572viciousPaths (BOI18_paths)C++17
100 / 100
326 ms56680 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define si second typedef pair<int,int> pi; typedef tuple<int,int,int> ti; template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;} template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;} void debug_out() {cerr<<endl;} template <typename Head, typename... Tail> void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);} #define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) const int N = 300010; int n,m,k; int c[N]; vector<int> g[N]; ll dp[40][N], ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin.exceptions(ios::badbit|ios::failbit); cin>>n>>m>>k; for (int i = 1; i <= n; ++i) { cin >> c[i]; --c[i]; } for (int i = 1; i <= m; ++i) { int u,v; cin >>u>>v; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i <= n; ++i) dp[(1<<c[i])][i]=1; for (int i = 1; i < (1<<k); ++i) { for (int j = 1; j <= n; ++j) { if (!(i&(1<<c[j]))) continue; int p = i^(1<<c[j]); for (auto v: g[j]) { dp[i][j] += dp[p][v]; } } } for (int i = 1; i < (1<<k); ++i) { if (__builtin_popcount(i)==1) continue; for (int j = 1; j <= n; ++j) ans += dp[i][j]; } cout << ans; 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...