Submission #151148

#TimeUsernameProblemLanguageResultExecution timeMemory
151148BlagojcePaths (BOI18_paths)C++11
23 / 100
3043 ms13872 KiB
#include <bits/stdc++.h> #define fr(i, n, m) for(int i = (n); i < (m); i ++) #define pb push_back #define st first #define nd second #define pq priority_queue #define all(x) begin(x),end(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; ll const inf = 1e9; ll const mod = 1e9 + 7; ld const eps = 1e-9; int n, m, k; int col[300005]; vector<int> g[300005]; void input(){ cin >> n >> m >> k; fr(i, 0, n){ cin >> col[i]; --col[i]; } fr(i, 0, m){ int a, b; cin >> a >> b; --a,--b; g[a].pb(b); g[b].pb(a); } } ll dfs(int u, int bit){ ll cnt = 0; for(auto e : g[u]){ if((bit&(1 << col[e])) == 0){ cnt += dfs(e,(bit|(1<<col[e]))) + 1; } } return cnt; } void solve(){ ll ANS = 0; fr(i, 0, n){ ANS += dfs(i, (1 << col[i])); } cout << ANS << endl; } int main() { input(); solve(); 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...