Submission #873319

#TimeUsernameProblemLanguageResultExecution timeMemory
873319bobbilykingPaths (BOI18_paths)C++17
100 / 100
292 ms100476 KiB
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<math.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pl; #define K first #define V second #define G(x) ll x; cin >> x; #define GD(x) ld x; cin >> x; #define GS(s) string s; cin >> s; #define EX(x) { cout << x << '\n'; exit(0); } #define A(a) (a).begin(), (a).end() #define F(i, l, r) for (ll i = (l); i < r; ++i) #define NN 300010 #define M 1000000007 // 998244353 ll dp[NN][1<<5]; vector<ll> adj[NN]; ll col[NN]; ll rec(ll i, ll bm) { auto &DP = dp[i][bm]; if (!~DP) { DP = 1; for (auto x: adj[i]) if (!((1<<col[x])&bm)) { DP += rec(x, bm|(1<<col[x])); } } return DP; } int main(){ // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); G(n) G(m) G(k) F(i, 1, n+1) { cin >> col[i]; --col[i]; } while(m--){ G(x) G(y) adj[x].push_back(y); adj[y].push_back(x); } memset(dp, -1, sizeof dp); ll ans = 0; F(i, 1, n+1) { // cout << i << ": " << rec(i, 1<<col[i]) << endl; ans += rec(i, 1<<col[i]); } cout << ans-n << '\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...